forked from microsoft/mssql-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLServerCallableStatement.java
3012 lines (2714 loc) · 142 KB
/
SQLServerCallableStatement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Microsoft JDBC Driver for SQL Server
*
* Copyright(c) Microsoft Corporation All rights reserved.
*
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* CallableStatement implements JDBC callable statements. CallableStatement allows the caller to specify the procedure name to call along with input
* parameter value and output parameter types. Callable statement also allows the return of a return status with the ? = call( ?, ..) JDBC syntax
* <p>
* The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those
* details.
*/
public class SQLServerCallableStatement extends SQLServerPreparedStatement implements ISQLServerCallableStatement {
/** the call param names */
private ArrayList<String> paramNames;
/** Number of registered OUT parameters */
int nOutParams = 0;
/** number of out params assigned already */
int nOutParamsAssigned = 0;
/** The index of the out params indexed - internal index */
private int outParamIndex = -1;
// The last out param accessed.
private Parameter lastParamAccessed;
/** Currently active Stream Note only one stream can be active at a time */
private Closeable activeStream;
// Internal function used in tracing
String getClassNameInternal() {
return "SQLServerCallableStatement";
}
/**
* Create a new callable statement.
*
* @param connection
* the connection
* @param sql
* the users call syntax
* @param nRSType
* the result set type
* @param nRSConcur
* the result set concurrency
* @param stmtColEncSetting
* the statement column encryption setting
* @throws SQLServerException
*/
SQLServerCallableStatement(SQLServerConnection connection,
String sql,
int nRSType,
int nRSConcur,
SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException {
super(connection, sql, nRSType, nRSConcur, stmtColEncSetting);
}
public void registerOutParameter(int index,
int sqlType) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {new Integer(index), new Integer(sqlType)});
checkClosed();
if (index < 1 || index > inOutParam.length) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_indexOutOfRange"));
Object[] msgArgs = {new Integer(index)};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "7009", false);
}
// REF_CURSOR 2012 is a special type - should throw SQLFeatureNotSupportedException as per spec
// but this will require changing API to throw SQLException.
// This should be reviewed in 4199060
if (2012 == sqlType) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_featureNotSupported"));
Object[] msgArgs = {"REF_CURSOR"};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), null, false);
}
JDBCType jdbcType = JDBCType.of(sqlType);
// Registering an OUT parameter is an indication that the app is done
// with the results from any previous execution
discardLastExecutionResults();
// OUT parameters registered as unsupported JDBC types map to BINARY
// so that they are minimally supported.
if (jdbcType.isUnsupported())
jdbcType = JDBCType.BINARY;
Parameter param = inOutParam[index - 1];
assert null != param;
// If the parameter was not previously registered for OUTPUT then
// it is added to the set of OUTPUT parameters now.
if (!param.isOutput())
++nOutParams;
// (Re)register the parameter for OUTPUT with the specified SQL type
// overriding any previous registration with another SQL type.
param.registerForOutput(jdbcType, connection);
switch (sqlType) {
case microsoft.sql.Types.DATETIME:
param.setOutScale(3);
break;
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
case microsoft.sql.Types.DATETIMEOFFSET:
param.setOutScale(7);
break;
default:
break;
}
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
/**
* Locate any output parameter values returned from the procedure call
*/
private Parameter getOutParameter(int i) throws SQLServerException {
// Process any remaining result sets and update counts. This positions
// us for retrieving the OUT parameters. Note that after retrieving
// an OUT parameter, an SQLException is thrown if the application tries
// to go back and process the results.
processResults();
// if this item has been indexed already leave!
if (inOutParam[i - 1] == lastParamAccessed || inOutParam[i - 1].isValueGotten())
return inOutParam[i - 1];
// Skip OUT parameters (buffering them as we go) until we
// reach the one we're looking for.
while (outParamIndex != i - 1)
skipOutParameters(1, false);
return inOutParam[i - 1];
}
void startResults() {
super.startResults();
outParamIndex = -1;
nOutParamsAssigned = 0;
lastParamAccessed = null;
assert null == activeStream;
}
void processBatch() throws SQLServerException {
processResults();
// If there were any OUT parameters, then process them
// and the rest of the batch that follows them. If there were
// no OUT parameters, than the entire batch was already processed
// in the processResults call above.
assert nOutParams >= 0;
if (nOutParams > 0) {
processOutParameters();
processBatchRemainder();
}
}
final void processOutParameters() throws SQLServerException {
assert nOutParams > 0;
assert null != inOutParam;
// make sure if we have active streams they are closed out.
closeActiveStream();
// First, discard all of the previously indexed OUT parameters up to,
// but not including, the last-indexed parameter.
if (outParamIndex >= 0) {
// Note: It doesn't matter that they're not cleared in the order they
// appear in the response stream. What counts is that at the end
// none of them has any TDSReaderMarks holding onto any portion of
// the response stream.
for (int index = 0; index < inOutParam.length; ++index) {
if (index != outParamIndex && inOutParam[index].isValueGotten()) {
assert inOutParam[index].isOutput();
inOutParam[index].resetOutputValue();
}
}
}
// Next, if there are any unindexed parameters left then discard them too.
assert nOutParamsAssigned <= nOutParams;
if (nOutParamsAssigned < nOutParams)
skipOutParameters(nOutParams - nOutParamsAssigned, true);
// Finally, skip the last-indexed parameter. If there were no unindexed parameters
// in the previous step, then this is the last-indexed parameter left from the first
// step. If we skipped unindexed parameters in the previous step, then this is the
// last-indexed parameter left at the end of that step.
if (outParamIndex >= 0) {
inOutParam[outParamIndex].skipValue(resultsReader(), true);
inOutParam[outParamIndex].resetOutputValue();
outParamIndex = -1;
}
}
/**
* Processes the remainder of the batch up to the final or batch-terminating DONE token that marks the end of a sp_[cursor][prep]exec stored
* procedure call.
*/
private void processBatchRemainder() throws SQLServerException {
final class ExecDoneHandler extends TDSTokenHandler {
ExecDoneHandler() {
super("ExecDoneHandler");
}
boolean onDone(TDSReader tdsReader) throws SQLServerException {
// Consume the done token and decide what to do with it...
StreamDone doneToken = new StreamDone();
doneToken.setFromTDS(tdsReader);
// If this is a non-final batch-terminating DONE token,
// then stop parsing the response now and set up for
// the next batch.
if (doneToken.wasRPCInBatch()) {
startResults();
return false;
}
// Continue processing so that we pick up ENVCHANGE tokens.
// Parsing stops automatically on response EOF.
return true;
}
}
ExecDoneHandler execDoneHandler = new ExecDoneHandler();
TDSParser.parse(resultsReader(), execDoneHandler);
}
private void skipOutParameters(int numParamsToSkip,
boolean discardValues) throws SQLServerException {
/** TDS token handler for locating OUT parameters (RETURN_VALUE tokens) in the response token stream */
final class OutParamHandler extends TDSTokenHandler {
final StreamRetValue srv = new StreamRetValue();
private boolean foundParam;
final boolean foundParam() {
return foundParam;
}
OutParamHandler() {
super("OutParamHandler");
}
final void reset() {
foundParam = false;
}
boolean onRetValue(TDSReader tdsReader) throws SQLServerException {
srv.setFromTDS(tdsReader);
foundParam = true;
return false;
}
}
OutParamHandler outParamHandler = new OutParamHandler();
// Index the application OUT parameters
assert numParamsToSkip <= nOutParams - nOutParamsAssigned;
for (int paramsSkipped = 0; paramsSkipped < numParamsToSkip; ++paramsSkipped) {
// Discard the last-indexed parameter by skipping over it and
// discarding the value if it is no longer needed.
if (-1 != outParamIndex) {
inOutParam[outParamIndex].skipValue(resultsReader(), discardValues);
if (discardValues)
inOutParam[outParamIndex].resetOutputValue();
}
// Look for the next parameter value in the response.
outParamHandler.reset();
TDSParser.parse(resultsReader(), outParamHandler);
// If we don't find it, then most likely the server encountered some error that
// was bad enough to halt statement execution before returning OUT params, but
// not necessarily bad enough to close the connection.
if (!outParamHandler.foundParam()) {
// If we were just going to discard the OUT parameters we found anyway,
// then it's no problem that we didn't find any of them. For exmaple,
// when we are closing or reexecuting this CallableStatement (that is,
// calling in through processResponse), we don't care that execution
// failed to return the OUT parameters.
if (discardValues)
break;
// If we were asked to retain the OUT parameters as we skip past them,
// then report an error if we did not find any.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_valueNotSetForParameter"));
Object[] msgArgs = {new Integer(outParamIndex + 1)};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), null, false);
}
// In Yukon and later, large Object output parameters are reordered to appear at
// the end of the stream. First group of small parameters is sent, followed by
// group of large output parameters. There is no reordering within the groups.
// Note that parameter ordinals are 0-indexed and that the return status is not
// considered to be an output parameter.
outParamIndex = outParamHandler.srv.getOrdinalOrLength();
// Statements need to have their out param indices adjusted by the number
// of sp_[cursor][prep]exec params.
outParamIndex -= outParamIndexAdjustment;
if ((outParamIndex < 0 || outParamIndex >= inOutParam.length) || (!inOutParam[outParamIndex].isOutput())) {
getStatementLogger().info(toString() + " Unexpected outParamIndex: " + outParamIndex + "; adjustment: " + outParamIndexAdjustment);
connection.throwInvalidTDS();
}
++nOutParamsAssigned;
}
}
/* L0 */ public void registerOutParameter(int index,
int sqlType,
String typeName) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "registerOutParameter", new Object[] {new Integer(index), new Integer(sqlType), typeName});
checkClosed();
registerOutParameter(index, sqlType);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
/* L0 */ public void registerOutParameter(int index,
int sqlType,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
new Object[] {new Integer(index), new Integer(sqlType), new Integer(scale)});
checkClosed();
registerOutParameter(index, sqlType);
inOutParam[index - 1].setOutScale(scale);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
public void registerOutParameter(int index,
int sqlType,
int precision,
int scale) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "registerOutParameter",
new Object[] {new Integer(index), new Integer(sqlType), new Integer(scale), new Integer(precision)});
checkClosed();
registerOutParameter(index, sqlType);
inOutParam[index - 1].setValueLength(precision);
inOutParam[index - 1].setOutScale(scale);
loggerExternal.exiting(getClassNameLogging(), "registerOutParameter");
}
/* ---------------------- JDBC API: Get Output Params -------------------------- */
private Parameter getterGetParam(int index) throws SQLServerException {
checkClosed();
// Check for valid index
if (index < 1 || index > inOutParam.length) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidOutputParameter"));
Object[] msgArgs = {new Integer(index)};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", false);
}
// Check index refers to a registered OUT parameter
if (!inOutParam[index - 1].isOutput()) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_outputParameterNotRegisteredForOutput"));
Object[] msgArgs = {new Integer(index)};
SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", true);
}
// If we haven't executed the statement yet then throw a nice friendly exception.
if (!wasExecuted())
SQLServerException.makeFromDriverError(connection, this, SQLServerException.getErrString("R_statementMustBeExecuted"), "07009", false);
resultsReader().getCommand().checkForInterrupt();
closeActiveStream();
if (getStatementLogger().isLoggable(java.util.logging.Level.FINER))
getStatementLogger().finer(toString() + " Getting Param:" + index);
// Dynamically load OUT params from TDS response buffer
lastParamAccessed = getOutParameter(index);
return lastParamAccessed;
}
private Object getValue(int parameterIndex,
JDBCType jdbcType) throws SQLServerException {
return getterGetParam(parameterIndex).getValue(jdbcType, null, null, resultsReader());
}
private Object getValue(int parameterIndex,
JDBCType jdbcType,
Calendar cal) throws SQLServerException {
return getterGetParam(parameterIndex).getValue(jdbcType, null, cal, resultsReader());
}
private Object getStream(int parameterIndex,
StreamType streamType) throws SQLServerException {
Object value = getterGetParam(parameterIndex).getValue(streamType.getJDBCType(),
new InputStreamGetterArgs(streamType, getIsResponseBufferingAdaptive(), getIsResponseBufferingAdaptive(), toString()), null, // calendar
resultsReader());
activeStream = (Closeable) value;
return value;
}
private Object getSQLXMLInternal(int parameterIndex) throws SQLServerException {
SQLServerSQLXML value = (SQLServerSQLXML) getterGetParam(parameterIndex).getValue(JDBCType.SQLXML,
new InputStreamGetterArgs(StreamType.SQLXML, getIsResponseBufferingAdaptive(), getIsResponseBufferingAdaptive(), toString()), null, // calendar
resultsReader());
if (null != value)
activeStream = value.getStream();
return value;
}
public int getInt(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getInt", index);
checkClosed();
Integer value = (Integer) getValue(index, JDBCType.INTEGER);
loggerExternal.exiting(getClassNameLogging(), "getInt", value);
return null != value ? value.intValue() : 0;
}
public int getInt(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getInt", sCol);
checkClosed();
Integer value = (Integer) getValue(findColumn(sCol), JDBCType.INTEGER);
loggerExternal.exiting(getClassNameLogging(), "getInt", value);
return null != value ? value.intValue() : 0;
}
public String getString(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getString", index);
checkClosed();
String value = (String) getValue(index, JDBCType.CHAR);
loggerExternal.exiting(getClassNameLogging(), "getString", value);
return value;
}
public String getString(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getString", sCol);
checkClosed();
String value = (String) getValue(findColumn(sCol), JDBCType.CHAR);
loggerExternal.exiting(getClassNameLogging(), "getString", value);
return value;
}
public final String getNString(int parameterIndex) throws SQLException {
DriverJDBCVersion.checkSupportsJDBC4();
loggerExternal.entering(getClassNameLogging(), "getNString", parameterIndex);
checkClosed();
String value = (String) getValue(parameterIndex, JDBCType.NCHAR);
loggerExternal.exiting(getClassNameLogging(), "getNString", value);
return value;
}
public final String getNString(String parameterName) throws SQLException {
DriverJDBCVersion.checkSupportsJDBC4();
loggerExternal.entering(getClassNameLogging(), "getNString", parameterName);
checkClosed();
String value = (String) getValue(findColumn(parameterName), JDBCType.NCHAR);
loggerExternal.exiting(getClassNameLogging(), "getNString", value);
return value;
}
@Deprecated
public BigDecimal getBigDecimal(int parameterIndex,
int scale) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getBigDecimal", new Object[] {Integer.valueOf(parameterIndex), Integer.valueOf(scale)});
checkClosed();
BigDecimal value = (BigDecimal) getValue(parameterIndex, JDBCType.DECIMAL);
if (null != value)
value = value.setScale(scale, BigDecimal.ROUND_DOWN);
loggerExternal.exiting(getClassNameLogging(), "getBigDecimal", value);
return value;
}
@Deprecated
public BigDecimal getBigDecimal(String parameterName,
int scale) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getBigDecimal", new Object[] {parameterName, Integer.valueOf(scale)});
checkClosed();
BigDecimal value = (BigDecimal) getValue(findColumn(parameterName), JDBCType.DECIMAL);
if (null != value)
value = value.setScale(scale, BigDecimal.ROUND_DOWN);
loggerExternal.exiting(getClassNameLogging(), "getBigDecimal", value);
return value;
}
public boolean getBoolean(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBoolean", index);
checkClosed();
Boolean value = (Boolean) getValue(index, JDBCType.BIT);
loggerExternal.exiting(getClassNameLogging(), "getBoolean", value);
return null != value ? value.booleanValue() : false;
}
public boolean getBoolean(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBoolean", sCol);
checkClosed();
Boolean value = (Boolean) getValue(findColumn(sCol), JDBCType.BIT);
loggerExternal.exiting(getClassNameLogging(), "getBoolean", value);
return null != value ? value.booleanValue() : false;
}
public byte getByte(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getByte", index);
checkClosed();
Short shortValue = (Short) getValue(index, JDBCType.TINYINT);
byte byteValue = (null != shortValue) ? shortValue.byteValue() : 0;
loggerExternal.exiting(getClassNameLogging(), "getByte", byteValue);
return byteValue;
}
public byte getByte(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getByte", sCol);
checkClosed();
Short shortValue = (Short) getValue(findColumn(sCol), JDBCType.TINYINT);
byte byteValue = (null != shortValue) ? shortValue.byteValue() : 0;
loggerExternal.exiting(getClassNameLogging(), "getByte", byteValue);
return byteValue;
}
public byte[] getBytes(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBytes", index);
checkClosed();
byte[] value = (byte[]) getValue(index, JDBCType.BINARY);
loggerExternal.exiting(getClassNameLogging(), "getBytes", value);
return value;
}
public byte[] getBytes(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBytes", sCol);
checkClosed();
byte[] value = (byte[]) getValue(findColumn(sCol), JDBCType.BINARY);
loggerExternal.exiting(getClassNameLogging(), "getBytes", value);
return value;
}
public Date getDate(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getDate", index);
checkClosed();
java.sql.Date value = (java.sql.Date) getValue(index, JDBCType.DATE);
loggerExternal.exiting(getClassNameLogging(), "getDate", value);
return value;
}
public Date getDate(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getDate", sCol);
checkClosed();
java.sql.Date value = (java.sql.Date) getValue(findColumn(sCol), JDBCType.DATE);
loggerExternal.exiting(getClassNameLogging(), "getDate", value);
return value;
}
public Date getDate(int index,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {index, cal});
checkClosed();
java.sql.Date value = (java.sql.Date) getValue(index, JDBCType.DATE, cal);
loggerExternal.exiting(getClassNameLogging(), "getDate", value);
return value;
}
public Date getDate(String sCol,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDate", new Object[] {sCol, cal});
checkClosed();
java.sql.Date value = (java.sql.Date) getValue(findColumn(sCol), JDBCType.DATE, cal);
loggerExternal.exiting(getClassNameLogging(), "getDate", value);
return value;
}
public double getDouble(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getDouble", index);
checkClosed();
Double value = (Double) getValue(index, JDBCType.DOUBLE);
loggerExternal.exiting(getClassNameLogging(), "getDouble", value);
return null != value ? value.doubleValue() : 0;
}
public double getDouble(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getDouble", sCol);
checkClosed();
Double value = (Double) getValue(findColumn(sCol), JDBCType.DOUBLE);
loggerExternal.exiting(getClassNameLogging(), "getDouble", value);
return null != value ? value.doubleValue() : 0;
}
public float getFloat(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getFloat", index);
checkClosed();
Float value = (Float) getValue(index, JDBCType.REAL);
loggerExternal.exiting(getClassNameLogging(), "getFloat", value);
return null != value ? value.floatValue() : 0;
}
public float getFloat(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getFloat", sCol);
checkClosed();
Float value = (Float) getValue(findColumn(sCol), JDBCType.REAL);
loggerExternal.exiting(getClassNameLogging(), "getFloat", value);
return null != value ? value.floatValue() : 0;
}
public long getLong(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getLong", index);
checkClosed();
Long value = (Long) getValue(index, JDBCType.BIGINT);
loggerExternal.exiting(getClassNameLogging(), "getLong", value);
return null != value ? value.longValue() : 0;
}
public long getLong(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getLong", sCol);
checkClosed();
Long value = (Long) getValue(findColumn(sCol), JDBCType.BIGINT);
loggerExternal.exiting(getClassNameLogging(), "getLong", value);
return null != value ? value.longValue() : 0;
}
public Object getObject(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getObject", index);
checkClosed();
Object value = getValue(index, getterGetParam(index).getJdbcTypeSetByUser() != null ? getterGetParam(index).getJdbcTypeSetByUser()
: getterGetParam(index).getJdbcType());
loggerExternal.exiting(getClassNameLogging(), "getObject", value);
return value;
}
public <T> T getObject(int index,
Class<T> type) throws SQLException {
DriverJDBCVersion.checkSupportsJDBC41();
// The driver currently does not implement the optional JDBC APIs
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
}
public Object getObject(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getObject", sCol);
checkClosed();
int parameterIndex = findColumn(sCol);
Object value = getValue(parameterIndex, getterGetParam(parameterIndex).getJdbcTypeSetByUser() != null
? getterGetParam(parameterIndex).getJdbcTypeSetByUser() : getterGetParam(parameterIndex).getJdbcType());
loggerExternal.exiting(getClassNameLogging(), "getObject", value);
return value;
}
public <T> T getObject(String sCol,
Class<T> type) throws SQLException {
DriverJDBCVersion.checkSupportsJDBC41();
// The driver currently does not implement the optional JDBC APIs
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
}
public short getShort(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getShort", index);
checkClosed();
Short value = (Short) getValue(index, JDBCType.SMALLINT);
loggerExternal.exiting(getClassNameLogging(), "getShort", value);
return null != value ? value.shortValue() : 0;
}
public short getShort(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getShort", sCol);
checkClosed();
Short value = (Short) getValue(findColumn(sCol), JDBCType.SMALLINT);
loggerExternal.exiting(getClassNameLogging(), "getShort", value);
return null != value ? value.shortValue() : 0;
}
public Time getTime(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getTime", index);
checkClosed();
java.sql.Time value = (java.sql.Time) getValue(index, JDBCType.TIME);
loggerExternal.exiting(getClassNameLogging(), "getTime", value);
return value;
}
public Time getTime(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getTime", sCol);
checkClosed();
java.sql.Time value = (java.sql.Time) getValue(findColumn(sCol), JDBCType.TIME);
loggerExternal.exiting(getClassNameLogging(), "getTime", value);
return value;
}
public Time getTime(int index,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {index, cal});
checkClosed();
java.sql.Time value = (java.sql.Time) getValue(index, JDBCType.TIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getTime", value);
return value;
}
public Time getTime(String sCol,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTime", new Object[] {sCol, cal});
checkClosed();
java.sql.Time value = (java.sql.Time) getValue(findColumn(sCol), JDBCType.TIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getTime", value);
return value;
}
public Timestamp getTimestamp(int index) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", index);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.TIMESTAMP);
loggerExternal.exiting(getClassNameLogging(), "getTimestamp", value);
return value;
}
public Timestamp getTimestamp(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getTimestamp", sCol);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(sCol), JDBCType.TIMESTAMP);
loggerExternal.exiting(getClassNameLogging(), "getTimestamp", value);
return value;
}
public Timestamp getTimestamp(int index,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {index, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.TIMESTAMP, cal);
loggerExternal.exiting(getClassNameLogging(), "getTimestamp", value);
return value;
}
public Timestamp getTimestamp(String name,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getTimestamp", new Object[] {name, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(name), JDBCType.TIMESTAMP, cal);
loggerExternal.exiting(getClassNameLogging(), "getTimestamp", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language.
*
* @param index
* the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getDateTime(int index) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", index);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.DATETIME);
loggerExternal.exiting(getClassNameLogging(), "getDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language.
*
* @param sCol
* the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the
* column
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getDateTime(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getDateTime", sCol);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(sCol), JDBCType.DATETIME);
loggerExternal.exiting(getClassNameLogging(), "getDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
* not store timezone information.
*
* @param index
* the first column is 1, the second is 2, ...
* @param cal
* the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getDateTime(int index,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {index, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.DATETIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language. This method uses the given calendar to construct an appropriate millisecond value for the timestamp if the underlying database does
* not store timezone information.
*
* @param name
* the name of the column
* @param cal
* the java.util.Calendar object to use in constructing the dateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getDateTime(String name,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTime", new Object[] {name, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(name), JDBCType.DATETIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language.
*
* @param index
* the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getSmallDateTime(int index) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", index);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.SMALLDATETIME);
loggerExternal.exiting(getClassNameLogging(), "getSmallDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language.
*
* @param sCol
* The name of a column.
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getSmallDateTime(String sCol) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", sCol);
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(sCol), JDBCType.SMALLDATETIME);
loggerExternal.exiting(getClassNameLogging(), "getSmallDateTime", value);
return value;
}
/**
* Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming
* language.
*
* @param index
* the first column is 1, the second is 2, ...
* @param cal
* the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getSmallDateTime(int index,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {index, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(index, JDBCType.SMALLDATETIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getSmallDateTime", value);
return value;
}
/**
*
* @param name
* The name of a column
* @param cal
* the java.util.Calendar object to use in constructing the smalldateTime
* @return the column value; if the value is SQL NULL, the value returned is null
* @throws SQLServerException
* when an error occurs
*/
public Timestamp getSmallDateTime(String name,
Calendar cal) throws SQLServerException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getSmallDateTime", new Object[] {name, cal});
checkClosed();
java.sql.Timestamp value = (java.sql.Timestamp) getValue(findColumn(name), JDBCType.SMALLDATETIME, cal);
loggerExternal.exiting(getClassNameLogging(), "getSmallDateTime", value);
return value;
}
public microsoft.sql.DateTimeOffset getDateTimeOffset(int index) throws SQLException {
if (loggerExternal.isLoggable(java.util.logging.Level.FINER))
loggerExternal.entering(getClassNameLogging(), "getDateTimeOffset", index);
checkClosed();
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!connection.isKatmaiOrLater())
throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
null);
microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(index, JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
return value;
}
public microsoft.sql.DateTimeOffset getDateTimeOffset(String sCol) throws SQLException {
loggerExternal.entering(getClassNameLogging(), "getDateTimeOffset", sCol);
checkClosed();
// DateTimeOffset is not supported with SQL Server versions earlier than Katmai
if (!connection.isKatmaiOrLater())
throw new SQLServerException(SQLServerException.getErrString("R_notSupported"), SQLState.DATA_EXCEPTION_NOT_SPECIFIC, DriverError.NOT_SET,
null);
microsoft.sql.DateTimeOffset value = (microsoft.sql.DateTimeOffset) getValue(findColumn(sCol), JDBCType.DATETIMEOFFSET);
loggerExternal.exiting(getClassNameLogging(), "getDateTimeOffset", value);
return value;
}
/* L0 */ public boolean wasNull() throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "wasNull");
checkClosed();
boolean bWasNull = false;
if (null != lastParamAccessed) {
bWasNull = lastParamAccessed.isNull();
}
loggerExternal.exiting(getClassNameLogging(), "wasNull", bWasNull);
return bWasNull;
}