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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 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 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
|
//------------------------------------------------------------------------------
// <copyright file="ColumnBinding.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Data.OleDb {
using System;
using System.Diagnostics;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
sealed internal class ColumnBinding {
// shared with other ColumnBindings
private readonly OleDbDataReader _dataReader; // HCHAPTER
private readonly RowBinding _rowbinding; // for native buffer interaction
private readonly Bindings _bindings;
// unique to this ColumnBinding
private readonly OleDbParameter _parameter; // output value
private readonly int _parameterChangeID;
private readonly int _offsetStatus;
private readonly int _offsetLength;
private readonly int _offsetValue;
private readonly int _ordinal;
private readonly int _maxLen;
private readonly short _wType;
private readonly byte _precision;
private readonly int _index;
private readonly int _indexForAccessor; // HCHAPTER
private readonly int _indexWithinAccessor; // HCHAPTER
private readonly bool _ifIRowsetElseIRow;
// unique per current input value
private int _valueBindingOffset;
private int _valueBindingSize;
internal StringMemHandle _sptr;
private GCHandle _pinnedBuffer;
// value is cached via property getters so the original may be released
// for Value, ValueByteArray, ValueString, ValueVariant
private object _value;
internal ColumnBinding(OleDbDataReader dataReader, int index, int indexForAccessor, int indexWithinAccessor,
OleDbParameter parameter, RowBinding rowbinding, Bindings bindings, tagDBBINDING binding, int offset,
bool ifIRowsetElseIRow) {
Debug.Assert(null != rowbinding, "null rowbinding");
Debug.Assert(null != bindings, "null bindings");
Debug.Assert(ODB.SizeOf_tagDBBINDING <= offset, "invalid offset" + offset);
_dataReader = dataReader;
_rowbinding = rowbinding;
_bindings = bindings;
_index = index;
_indexForAccessor = indexForAccessor;
_indexWithinAccessor = indexWithinAccessor;
if (null != parameter) {
_parameter = parameter;
_parameterChangeID = parameter.ChangeID;
}
_offsetStatus = binding.obStatus.ToInt32() + offset;
_offsetLength = binding.obLength.ToInt32() + offset;
_offsetValue = binding.obValue.ToInt32() + offset;
Debug.Assert(0 <= _offsetStatus, "negative _offsetStatus");
Debug.Assert(0 <= _offsetLength, "negative _offsetLength");
Debug.Assert(0 <= _offsetValue, "negative _offsetValue");
_ordinal = binding.iOrdinal.ToInt32();
_maxLen = binding.cbMaxLen.ToInt32();
_wType = binding.wType;
_precision = binding.bPrecision;
_ifIRowsetElseIRow = ifIRowsetElseIRow;
SetSize(Bindings.ParamSize.ToInt32());
}
internal Bindings Bindings {
get {
_bindings.CurrentIndex = IndexWithinAccessor;
return _bindings;
}
}
internal RowBinding RowBinding {
get { return _rowbinding; }
}
internal int ColumnBindingOrdinal {
get { return _ordinal; }
}
private int ColumnBindingMaxLen {
get { return _maxLen; }
}
private byte ColumnBindingPrecision {
get { return _precision; }
}
private short DbType {
get { return _wType; }
}
private Type ExpectedType {
get { return NativeDBType.FromDBType(DbType, false, false).dataType; }
}
internal int Index {
get { return _index; }
}
internal int IndexForAccessor {
get { return _indexForAccessor; }
}
internal int IndexWithinAccessor {
get { return _indexWithinAccessor; }
}
private int ValueBindingOffset { // offset within the value of where to start copying
get { return _valueBindingOffset; }
}
private int ValueBindingSize { // maximum size of the value to copy
get { return _valueBindingSize; }
}
internal int ValueOffset { // offset within the native buffer to put the value
get { return _offsetValue; }
}
private OleDbDataReader DataReader() {
Debug.Assert(null != _dataReader, "null DataReader");
return _dataReader;
}
internal bool IsParameterBindingInvalid(OleDbParameter parameter) {
Debug.Assert((null != _parameter) && (null != parameter), "null parameter");
return ((_parameter.ChangeID != _parameterChangeID) || (_parameter != parameter));
}
internal bool IsValueNull() {
return ((DBStatus.S_ISNULL == StatusValue())
|| (((NativeDBType.VARIANT == DbType) || (NativeDBType.PROPVARIANT == DbType))
&& (Convert.IsDBNull(ValueVariant()))));
}
private int LengthValue() {
int length;
if (_ifIRowsetElseIRow) {
length = RowBinding.ReadIntPtr(_offsetLength).ToInt32();
}
else { // WebData 94427
length = Bindings.DBColumnAccess[IndexWithinAccessor].cbDataLen.ToInt32();
}
return Math.Max(length, 0);
}
private void LengthValue(int value) {
Debug.Assert(0 <= value, "negative LengthValue");
RowBinding.WriteIntPtr(_offsetLength, (IntPtr)value);
}
internal OleDbParameter Parameter() {
Debug.Assert(null != _parameter, "null parameter");
return _parameter;
}
internal void ResetValue() {
_value = null;
StringMemHandle sptr = _sptr;
_sptr = null;
if (null != sptr) {
sptr.Dispose();
}
if (_pinnedBuffer.IsAllocated) {
_pinnedBuffer.Free();
}
}
internal DBStatus StatusValue() {
if (_ifIRowsetElseIRow) {
return (DBStatus) RowBinding.ReadInt32(_offsetStatus);
}
else { // WebData 94427
return (DBStatus) Bindings.DBColumnAccess[IndexWithinAccessor].dwStatus;
}
}
internal void StatusValue(DBStatus value) {
#if DEBUG
switch(value) {
case DBStatus.S_OK:
case DBStatus.S_ISNULL:
case DBStatus.S_DEFAULT:
break;
default:
Debug.Assert(false, "unexpected StatusValue");
break;
}
#endif
RowBinding.WriteInt32(_offsetStatus, (int)value);
}
internal void SetOffset(int offset) {
if (0 > offset) {
throw ADP.InvalidOffsetValue(offset);
}
_valueBindingOffset = Math.Max(offset, 0);
}
internal void SetSize(int size) {
_valueBindingSize = Math.Max(size, 0);
}
private void SetValueDBNull() {
LengthValue(0);
StatusValue(DBStatus.S_ISNULL);
RowBinding.WriteInt64(ValueOffset, 0); // safe because AlignDataSize forces 8 byte blocks
}
private void SetValueEmpty() {
LengthValue(0);
StatusValue(DBStatus.S_DEFAULT);
RowBinding.WriteInt64(ValueOffset, 0); // safe because AlignDataSize forces 8 byte blocks
}
internal Object Value() {
object value = _value;
if (null == value) {
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.EMPTY:
case NativeDBType.NULL:
value = DBNull.Value;
break;
case NativeDBType.I2:
value = Value_I2(); // Int16
break;
case NativeDBType.I4:
value = Value_I4(); // Int32
break;
case NativeDBType.R4:
value = Value_R4(); // Single
break;
case NativeDBType.R8:
value = Value_R8(); // Double
break;
case NativeDBType.CY:
value = Value_CY(); // Decimal
break;
case NativeDBType.DATE:
value = Value_DATE(); // DateTime
break;
case NativeDBType.BSTR:
value = Value_BSTR(); // String
break;
case NativeDBType.IDISPATCH:
value = Value_IDISPATCH(); // Object
break;
case NativeDBType.ERROR:
value = Value_ERROR(); // Int32
break;
case NativeDBType.BOOL:
value = Value_BOOL(); // Boolean
break;
case NativeDBType.VARIANT:
value = Value_VARIANT(); // Object
break;
case NativeDBType.IUNKNOWN:
value = Value_IUNKNOWN(); // Object
break;
case NativeDBType.DECIMAL:
value = Value_DECIMAL(); // Decimal
break;
case NativeDBType.I1:
value = (short) Value_I1(); // SByte->Int16
break;
case NativeDBType.UI1:
value = Value_UI1(); // Byte
break;
case NativeDBType.UI2:
value = (int) Value_UI2(); // UInt16->Int32
break;
case NativeDBType.UI4:
value = (long) Value_UI4(); // UInt32->Int64
break;
case NativeDBType.I8:
value = Value_I8(); // Int64
break;
case NativeDBType.UI8:
value = (Decimal) Value_UI8(); // UInt64->Decimal
break;
case NativeDBType.FILETIME:
value = Value_FILETIME(); // DateTime
break;
case NativeDBType.GUID:
value = Value_GUID(); // Guid
break;
case NativeDBType.BYTES:
value = Value_BYTES(); // Byte[]
break;
case NativeDBType.WSTR:
value = Value_WSTR(); // String
break;
case NativeDBType.NUMERIC:
value = Value_NUMERIC(); // Decimal
break;
case NativeDBType.DBDATE:
value = Value_DBDATE(); // DateTime
break;
case NativeDBType.DBTIME:
value = Value_DBTIME(); // TimeSpan
break;
case NativeDBType.DBTIMESTAMP:
value = Value_DBTIMESTAMP(); // DateTime
break;
case NativeDBType.PROPVARIANT:
value = Value_VARIANT(); // Object
break;
case NativeDBType.HCHAPTER:
value = Value_HCHAPTER(); // OleDbDataReader
break;
case (NativeDBType.BYREF | NativeDBType.BYTES):
value = Value_ByRefBYTES();
break;
case (NativeDBType.BYREF | NativeDBType.WSTR):
value = Value_ByRefWSTR();
break;
default:
throw ODB.GVtUnknown(DbType);
#if DEBUG
case NativeDBType.STR:
Debug.Assert(false, "should have bound as WSTR");
goto default;
case NativeDBType.VARNUMERIC:
Debug.Assert(false, "should have bound as NUMERIC");
goto default;
case NativeDBType.UDT:
Debug.Assert(false, "UDT binding should not have been encountered");
goto default;
case (NativeDBType.BYREF | NativeDBType.STR):
Debug.Assert(false, "should have bound as BYREF|WSTR");
goto default;
#endif
}
break;
case DBStatus.S_TRUNCATED:
switch(DbType) {
case NativeDBType.BYTES:
value = Value_BYTES();
break;
case NativeDBType.WSTR:
value = Value_WSTR();
break;
case (NativeDBType.BYREF | NativeDBType.BYTES):
value = Value_ByRefBYTES();
break;
case (NativeDBType.BYREF | NativeDBType.WSTR):
value = Value_ByRefWSTR();
break;
default:
throw ODB.GVtUnknown(DbType);
#if DEBUG
case NativeDBType.STR:
Debug.Assert(false, "should have bound as WSTR");
goto default;
case (NativeDBType.BYREF | NativeDBType.STR):
Debug.Assert(false, "should have bound as BYREF|WSTR");
goto default;
#endif
}
break;
case DBStatus.S_ISNULL:
case DBStatus.S_DEFAULT:
value = DBNull.Value;
break;
default:
throw CheckTypeValueStatusValue(); // MDAC 71644
}
_value = value;
}
return value;
}
internal void Value(object value) {
if (null == value) {
SetValueEmpty();
}
else if (Convert.IsDBNull(value)) {
SetValueDBNull();
}
else switch (DbType) {
case NativeDBType.EMPTY:
SetValueEmpty();
break;
case NativeDBType.NULL: // language null - no representation, use DBNull
SetValueDBNull();
break;
case NativeDBType.I2:
Value_I2((Int16) value);
break;
case NativeDBType.I4:
Value_I4((Int32) value);
break;
case NativeDBType.R4:
Value_R4((Single) value);
break;
case NativeDBType.R8:
Value_R8((Double) value);
break;
case NativeDBType.CY:
Value_CY((Decimal) value);
break;
case NativeDBType.DATE:
Value_DATE((DateTime) value);
break;
case NativeDBType.BSTR:
Value_BSTR((String) value);
break;
case NativeDBType.IDISPATCH:
Value_IDISPATCH(value);
break;
case NativeDBType.ERROR:
Value_ERROR((Int32) value);
break;
case NativeDBType.BOOL:
Value_BOOL((Boolean) value);
break;
case NativeDBType.VARIANT:
Value_VARIANT(value);
break;
case NativeDBType.IUNKNOWN:
Value_IUNKNOWN(value);
break;
case NativeDBType.DECIMAL:
Value_DECIMAL((Decimal) value);
break;
case NativeDBType.I1:
if (value is Int16) { // MDAC 60430
Value_I1(Convert.ToSByte((Int16)value, CultureInfo.InvariantCulture));
}
else {
Value_I1((SByte) value);
}
break;
case NativeDBType.UI1:
Value_UI1((Byte) value);
break;
case NativeDBType.UI2:
if (value is Int32) {
Value_UI2(Convert.ToUInt16((Int32)value, CultureInfo.InvariantCulture));
}
else {
Value_UI2((UInt16) value);
}
break;
case NativeDBType.UI4:
if (value is Int64) {
Value_UI4(Convert.ToUInt32((Int64)value, CultureInfo.InvariantCulture));
}
else {
Value_UI4((UInt32) value);
}
break;
case NativeDBType.I8:
Value_I8((Int64) value);
break;
case NativeDBType.UI8:
if (value is Decimal) {
Value_UI8(Convert.ToUInt64((Decimal)value, CultureInfo.InvariantCulture));
}
else {
Value_UI8((UInt64) value);
}
break;
case NativeDBType.FILETIME:
Value_FILETIME((DateTime) value);
break;
case NativeDBType.GUID:
Value_GUID((Guid) value);
break;
case NativeDBType.BYTES:
Value_BYTES((Byte[]) value);
break;
case NativeDBType.WSTR:
if (value is string) {
Value_WSTR((String) value);
}
else {
Value_WSTR((char[]) value);
}
break;
case NativeDBType.NUMERIC:
Value_NUMERIC((Decimal) value);
break;
case NativeDBType.DBDATE:
Value_DBDATE((DateTime) value);
break;
case NativeDBType.DBTIME:
Value_DBTIME((TimeSpan) value);
break;
case NativeDBType.DBTIMESTAMP:
Value_DBTIMESTAMP((DateTime) value);
break;
case NativeDBType.PROPVARIANT:
Value_VARIANT(value);
break;
case (NativeDBType.BYREF | NativeDBType.BYTES):
Value_ByRefBYTES((Byte[]) value);
break;
case (NativeDBType.BYREF | NativeDBType.WSTR):
if (value is string) {
Value_ByRefWSTR((String) value);
}
else {
Value_ByRefWSTR((char[])value);
}
break;
default:
Debug.Assert(false, "unknown DBTYPE");
throw ODB.SVtUnknown(DbType);
#if DEBUG
case NativeDBType.STR:
Debug.Assert(false, "Should have bound as WSTR");
goto default;
case NativeDBType.UDT:
Debug.Assert(false, "UDT binding should not have been encountered");
goto default;
case NativeDBType.HCHAPTER:
Debug.Assert(false, "not allowed to set HCHAPTER");
goto default;
case NativeDBType.VARNUMERIC:
Debug.Assert(false, "should have bound as NUMERIC");
goto default;
case (NativeDBType.BYREF | NativeDBType.STR):
Debug.Assert(false, "should have bound as BYREF|WSTR");
goto default;
#endif
}
}
internal Boolean Value_BOOL() {
Debug.Assert((NativeDBType.BOOL == DbType), "Value_BOOL");
Debug.Assert((DBStatus.S_OK == StatusValue()), "Value_BOOL");
Int16 value = RowBinding.ReadInt16(ValueOffset);
return (0 != value);
}
private void Value_BOOL(Boolean value) {
Debug.Assert((NativeDBType.BOOL == DbType), "Value_BOOL");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt16(ValueOffset, (short)(value ? ODB.VARIANT_TRUE : ODB.VARIANT_FALSE));
}
private String Value_BSTR() {
Debug.Assert((NativeDBType.BSTR == DbType), "Value_BSTR");
Debug.Assert((DBStatus.S_OK == StatusValue()), "Value_BSTR");
string value = "";
RowBinding bindings = RowBinding;
bool mustRelease = false;
RuntimeHelpers.PrepareConstrainedRegions();
try {
bindings.DangerousAddRef(ref mustRelease);
IntPtr ptr = bindings.ReadIntPtr(ValueOffset);
if (ADP.PtrZero != ptr) {
value = Marshal.PtrToStringBSTR(ptr);
}
}
finally {
if (mustRelease) {
bindings.DangerousRelease();
}
}
return value;
}
private void Value_BSTR(String value) {
Debug.Assert((null != value), "Value_BSTR null");
Debug.Assert((NativeDBType.BSTR == DbType), "Value_BSTR");
LengthValue(value.Length * 2); /* bytecount*/
StatusValue(DBStatus.S_OK);
RowBinding.SetBstrValue(ValueOffset, value);
}
private Byte[] Value_ByRefBYTES() {
Debug.Assert(((NativeDBType.BYREF | NativeDBType.BYTES) == DbType), "Value_ByRefBYTES");
Debug.Assert((DBStatus.S_OK == StatusValue()), "Value_ByRefBYTES");
byte[] value = null;
RowBinding bindings = RowBinding;
bool mustRelease = false;
RuntimeHelpers.PrepareConstrainedRegions();
try {
bindings.DangerousAddRef(ref mustRelease);
IntPtr ptr = bindings.ReadIntPtr(ValueOffset);
if (ADP.PtrZero != ptr) {
value = new byte[LengthValue()];
Marshal.Copy(ptr, value, 0, value.Length);
}
}
finally {
if (mustRelease) {
bindings.DangerousRelease();
}
}
return ((null != value) ? value : new byte[0]);
}
private void Value_ByRefBYTES(Byte[] value) {
Debug.Assert(null != value, "Value_ByRefBYTES null");
Debug.Assert((NativeDBType.BYREF | NativeDBType.BYTES) == DbType, "Value_ByRefBYTES");
// we expect the provider/server to apply the silent truncation when binding BY_REF
// if (value.Length < ValueBindingOffset) { throw "Offset must refer to a location within the value" }
int length = ((ValueBindingOffset < value.Length) ? (value.Length - ValueBindingOffset) : 0);
LengthValue(((0 < ValueBindingSize) ? Math.Min(ValueBindingSize, length) : length));
StatusValue(DBStatus.S_OK);
IntPtr ptr = ADP.PtrZero;
if (0 < length) { // avoid pinning empty byte[]
_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned);
ptr = _pinnedBuffer.AddrOfPinnedObject();
ptr = ADP.IntPtrOffset(ptr, ValueBindingOffset);
}
RowBinding.SetByRefValue(ValueOffset, ptr);
}
private String Value_ByRefWSTR() {
Debug.Assert((NativeDBType.BYREF | NativeDBType.WSTR) == DbType, "Value_ByRefWSTR");
Debug.Assert((DBStatus.S_OK == StatusValue()) || (DBStatus.S_TRUNCATED == StatusValue()), "Value_ByRefWSTR");
string value = "";
RowBinding bindings = RowBinding;
bool mustRelease = false;
RuntimeHelpers.PrepareConstrainedRegions();
try {
bindings.DangerousAddRef(ref mustRelease);
IntPtr ptr = bindings.ReadIntPtr(ValueOffset);
if (ADP.PtrZero != ptr) {
int charCount = LengthValue() / 2;
value = Marshal.PtrToStringUni(ptr, charCount);
}
}
finally {
if (mustRelease) {
bindings.DangerousRelease();
}
}
return value;
}
private void Value_ByRefWSTR(String value) {
Debug.Assert(null != value, "Value_ByRefWSTR null");
Debug.Assert((NativeDBType.BYREF | NativeDBType.WSTR) == DbType, "Value_ByRefWSTR");
// we expect the provider/server to apply the silent truncation when binding BY_REF
// if (value.Length < ValueBindingOffset) { throw "Offset must refer to a location within the value" }
int length = ((ValueBindingOffset < value.Length) ? (value.Length - ValueBindingOffset) : 0);
LengthValue(((0 < ValueBindingSize) ? Math.Min(ValueBindingSize, length) : length) * 2); /* charcount->bytecount*/
StatusValue(DBStatus.S_OK);
IntPtr ptr = ADP.PtrZero;
if (0 < length) { // avoid pinning empty string, i.e String.Empty
_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned);
ptr = _pinnedBuffer.AddrOfPinnedObject();
ptr = ADP.IntPtrOffset(ptr, ValueBindingOffset);
}
RowBinding.SetByRefValue(ValueOffset, ptr);
}
private void Value_ByRefWSTR(char[] value) {
Debug.Assert(null != value, "Value_ByRefWSTR null");
Debug.Assert((NativeDBType.BYREF | NativeDBType.WSTR) == DbType, "Value_ByRefWSTR");
// we expect the provider/server to apply the silent truncation when binding BY_REF
// if (value.Length < ValueBindingOffset) { throw "Offset must refer to a location within the value" }
int length = ((ValueBindingOffset < value.Length) ? (value.Length - ValueBindingOffset) : 0);
LengthValue(((0 < ValueBindingSize) ? Math.Min(ValueBindingSize, length) : length) * 2); /* charcount->bytecount*/
StatusValue(DBStatus.S_OK);
IntPtr ptr = ADP.PtrZero;
if (0 < length) { // avoid pinning empty char[]
_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned);
ptr = _pinnedBuffer.AddrOfPinnedObject();
ptr = ADP.IntPtrOffset(ptr, ValueBindingOffset);
}
RowBinding.SetByRefValue(ValueOffset, ptr);
}
private Byte[] Value_BYTES() {
Debug.Assert(NativeDBType.BYTES == DbType, "Value_BYTES");
Debug.Assert((DBStatus.S_OK == StatusValue()) || (DBStatus.S_TRUNCATED == StatusValue()), "Value_BYTES");
int byteCount = Math.Min(LengthValue(), ColumnBindingMaxLen);
byte[] value = new byte[byteCount];
RowBinding.ReadBytes(ValueOffset, value, 0, byteCount);
return value;
}
private void Value_BYTES(Byte[] value) {
Debug.Assert(null != value, "Value_BYTES null");
// we silently truncate when the user has specified a given Size
int bytecount = ((ValueBindingOffset < value.Length) ? Math.Min(value.Length - ValueBindingOffset, ColumnBindingMaxLen) : 0); // 70232
LengthValue(bytecount);
StatusValue(DBStatus.S_OK);
if (0 < bytecount) {
RowBinding.WriteBytes(ValueOffset, value, ValueBindingOffset, bytecount);
}
}
private Decimal Value_CY() {
Debug.Assert(NativeDBType.CY == DbType, "Value_CY");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_CY");
return Decimal.FromOACurrency(RowBinding.ReadInt64(ValueOffset));
}
private void Value_CY(Decimal value) {
Debug.Assert(NativeDBType.CY == DbType, "Value_CY");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt64(ValueOffset, Decimal.ToOACurrency(value));
}
private DateTime Value_DATE() {
Debug.Assert(NativeDBType.DATE == DbType, "Value_DATE");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_DATE");
return DateTime.FromOADate(RowBinding.ReadDouble(ValueOffset));
}
private void Value_DATE(DateTime value) {
Debug.Assert(NativeDBType.DATE == DbType, "Value_DATE");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteDouble(ValueOffset, value.ToOADate());
}
private DateTime Value_DBDATE() {
Debug.Assert(NativeDBType.DBDATE == DbType, "Value_DBDATE");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_DBDATE");
return RowBinding.ReadDate(ValueOffset);
}
private void Value_DBDATE(DateTime value) {
Debug.Assert(NativeDBType.DBDATE == DbType, "Value_DATE");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteDate(ValueOffset, value);
}
private TimeSpan Value_DBTIME() {
Debug.Assert(NativeDBType.DBTIME == DbType, "Value_DBTIME");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_DBTIME");
return RowBinding.ReadTime(ValueOffset);
}
private void Value_DBTIME(TimeSpan value) {
Debug.Assert(NativeDBType.DBTIME == DbType, "Value_DBTIME");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteTime(ValueOffset, value);
}
private DateTime Value_DBTIMESTAMP() {
Debug.Assert(NativeDBType.DBTIMESTAMP == DbType, "Value_DBTIMESTAMP");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_DBTIMESTAMP");
return RowBinding.ReadDateTime(ValueOffset);
}
private void Value_DBTIMESTAMP(DateTime value) {
Debug.Assert(NativeDBType.DBTIMESTAMP == DbType, "Value_DBTIMESTAMP");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteDateTime(ValueOffset, value);
}
private Decimal Value_DECIMAL() {
Debug.Assert(NativeDBType.DECIMAL == DbType, "Value_DECIMAL");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_DECIMAL");
int[] buffer = new int[4];
RowBinding.ReadInt32Array(ValueOffset, buffer, 0, 4);
return new Decimal(
buffer[2], // low
buffer[3], // mid
buffer[1], // high
(0 != (buffer[0] & unchecked((int)0x80000000))), // sign
unchecked((byte)((buffer[0] & unchecked((int)0x00FF0000)) >> 16))); // scale, MDAC 95080
}
private void Value_DECIMAL(Decimal value) {
Debug.Assert(NativeDBType.DECIMAL == DbType, "Value_DECIMAL");
/* pending breaking change approval
if (_precision < ((System.Data.SqlTypes.SqlDecimal) value).Precision) { // WebData 87236
throw ADP.ParameterValueOutOfRange(value);
}
*/
LengthValue(0);
StatusValue(DBStatus.S_OK);
int[] tmp = Decimal.GetBits(value);
int[] buffer = new int[4] {
tmp[3], tmp[2], tmp[0], tmp[1]
};
RowBinding.WriteInt32Array(ValueOffset, buffer, 0, 4);
}
private Int32 Value_ERROR() {
Debug.Assert(NativeDBType.ERROR == DbType, "Value_ERROR");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_ERROR");
return RowBinding.ReadInt32(ValueOffset);
}
private void Value_ERROR(Int32 value) {
Debug.Assert(NativeDBType.ERROR == DbType, "Value_ERROR");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt32(ValueOffset, value);
}
private DateTime Value_FILETIME() {
Debug.Assert(NativeDBType.FILETIME == DbType, "Value_FILETIME");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_FILETIME");
Int64 tmp = RowBinding.ReadInt64(ValueOffset);
return DateTime.FromFileTime(tmp);
}
private void Value_FILETIME(DateTime value) {
Debug.Assert(NativeDBType.FILETIME == DbType, "Value_FILETIME");
LengthValue(0);
StatusValue(DBStatus.S_OK);
Int64 tmp = value.ToFileTime();
RowBinding.WriteInt64(ValueOffset, tmp);
}
internal Guid Value_GUID() {
Debug.Assert(NativeDBType.GUID == DbType, "Value_GUID");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_GUID");
return RowBinding.ReadGuid(ValueOffset);
}
private void Value_GUID(Guid value) {
Debug.Assert(NativeDBType.GUID == DbType, "Value_GUID");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteGuid(ValueOffset, value);
}
internal OleDbDataReader Value_HCHAPTER() {
Debug.Assert(NativeDBType.HCHAPTER == DbType, "Value_HCHAPTER");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_HCHAPTER");
return DataReader().ResetChapter(IndexForAccessor, IndexWithinAccessor, RowBinding, ValueOffset);
}
private SByte Value_I1() {
Debug.Assert(NativeDBType.I1 == DbType, "Value_I1");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_I1");
byte value = RowBinding.ReadByte(ValueOffset);
return unchecked((SByte)value);
}
private void Value_I1(SByte value) {
Debug.Assert(NativeDBType.I1 == DbType, "Value_I1");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteByte(ValueOffset, unchecked((Byte) value));
}
internal Int16 Value_I2() {
Debug.Assert(NativeDBType.I2 == DbType, "Value_I2");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_I2");
return RowBinding.ReadInt16(ValueOffset);
}
private void Value_I2(Int16 value) {
Debug.Assert(NativeDBType.I2 == DbType, "Value_I2");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt16(ValueOffset, value);
}
private Int32 Value_I4() {
Debug.Assert(NativeDBType.I4 == DbType, "Value_I4");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_I4");
return RowBinding.ReadInt32(ValueOffset);
}
private void Value_I4(Int32 value) {
Debug.Assert(NativeDBType.I4 == DbType, "Value_I4");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt32(ValueOffset, value);
}
private Int64 Value_I8() {
Debug.Assert(NativeDBType.I8 == DbType, "Value_I8");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_I8");
return RowBinding.ReadInt64(ValueOffset);
}
private void Value_I8(Int64 value) {
Debug.Assert(NativeDBType.I8 == DbType, "Value_I8");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt64(ValueOffset, value);
}
private object Value_IDISPATCH() {
Debug.Assert(NativeDBType.IDISPATCH == DbType, "Value_IDISPATCH");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_IDISPATCH");
object value;
RowBinding bindings = RowBinding;
bool mustRelease = false;
RuntimeHelpers.PrepareConstrainedRegions();
try {
bindings.DangerousAddRef(ref mustRelease);
IntPtr ptr = bindings.ReadIntPtr(ValueOffset);
value = Marshal.GetObjectForIUnknown(ptr);
}
finally {
if (mustRelease) {
bindings.DangerousRelease();
}
}
return value;
}
private void Value_IDISPATCH(object value) {
//
(new System.Security.NamedPermissionSet("FullTrust")).Demand(); // MDAC 80727
Debug.Assert(NativeDBType.IDISPATCH == DbType, "Value_IDISPATCH");
LengthValue(0);
StatusValue(DBStatus.S_OK);
IntPtr ptr = Marshal.GetIDispatchForObject(value); // MDAC 80727
RowBinding.WriteIntPtr(ValueOffset, ptr);
}
private object Value_IUNKNOWN() {
Debug.Assert(NativeDBType.IUNKNOWN == DbType, "Value_IUNKNOWN");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_IUNKNOWN");
object value;
RowBinding bindings = RowBinding;
bool mustRelease = false;
RuntimeHelpers.PrepareConstrainedRegions();
try {
bindings.DangerousAddRef(ref mustRelease);
IntPtr ptr = bindings.ReadIntPtr(ValueOffset);
value = Marshal.GetObjectForIUnknown(ptr);
}
finally {
if (mustRelease) {
bindings.DangerousRelease();
}
}
return value;
}
private void Value_IUNKNOWN(object value) {
//
(new System.Security.NamedPermissionSet("FullTrust")).Demand(); // MDAC 80727
Debug.Assert(NativeDBType.IUNKNOWN == DbType, "Value_IUNKNOWN");
LengthValue(0);
StatusValue(DBStatus.S_OK);
IntPtr ptr = Marshal.GetIUnknownForObject(value); // MDAC 80727
RowBinding.WriteIntPtr(ValueOffset, ptr);
}
private Decimal Value_NUMERIC() {
Debug.Assert(NativeDBType.NUMERIC == DbType, "Value_NUMERIC");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_NUMERIC");
return RowBinding.ReadNumeric(ValueOffset);
}
private void Value_NUMERIC(Decimal value) {
Debug.Assert(NativeDBType.NUMERIC == DbType, "Value_NUMERIC");
/* pending breaking change approval
if (_precision < ((System.Data.SqlTypes.SqlDecimal) value).Precision) { // WebData 87236
throw ADP.ParameterValueOutOfRange(value);
}
*/
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteNumeric(ValueOffset, value, ColumnBindingPrecision);
}
private Single Value_R4() {
Debug.Assert(NativeDBType.R4 == DbType, "Value_R4");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_R4");
return RowBinding.ReadSingle(ValueOffset);
}
private void Value_R4(Single value) {
Debug.Assert(NativeDBType.R4 == DbType, "Value_R4");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteSingle(ValueOffset,value);
}
private Double Value_R8() {
Debug.Assert(NativeDBType.R8 == DbType, "Value_R8");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_R8");
return RowBinding.ReadDouble(ValueOffset);
}
private void Value_R8(Double value) {
Debug.Assert(NativeDBType.R8 == DbType, "Value_I4");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteDouble(ValueOffset, value);
}
private Byte Value_UI1() {
Debug.Assert(NativeDBType.UI1 == DbType, "Value_UI1");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_UI1");
return RowBinding.ReadByte(ValueOffset);
}
private void Value_UI1(Byte value) {
Debug.Assert(NativeDBType.UI1 == DbType, "Value_UI1");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteByte(ValueOffset, value);
}
internal UInt16 Value_UI2() {
Debug.Assert(NativeDBType.UI2 == DbType, "Value_UI2");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_UI2");
return unchecked((UInt16) RowBinding.ReadInt16(ValueOffset));
}
private void Value_UI2(UInt16 value) {
Debug.Assert(NativeDBType.UI2 == DbType, "Value_UI2");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt16(ValueOffset, unchecked((Int16) value));
}
internal UInt32 Value_UI4() {
Debug.Assert(NativeDBType.UI4 == DbType, "Value_UI4");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_UI4");
return unchecked((UInt32) RowBinding.ReadInt32(ValueOffset));
}
private void Value_UI4(UInt32 value) {
Debug.Assert(NativeDBType.UI4 == DbType, "Value_UI4");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt32(ValueOffset, unchecked((Int32) value));
}
internal UInt64 Value_UI8() {
Debug.Assert(NativeDBType.UI8 == DbType, "Value_UI8");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_UI8");
return unchecked((UInt64) RowBinding.ReadInt64(ValueOffset));
}
private void Value_UI8(UInt64 value) {
Debug.Assert(NativeDBType.UI8 == DbType, "Value_UI8");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.WriteInt64(ValueOffset, unchecked((Int64) value));
}
private String Value_WSTR() {
Debug.Assert(NativeDBType.WSTR == DbType, "Value_WSTR");
Debug.Assert((DBStatus.S_OK == StatusValue()) || (DBStatus.S_TRUNCATED == StatusValue()), "Value_WSTR");
Debug.Assert(2 < ColumnBindingMaxLen, "Value_WSTR");
int byteCount = Math.Min(LengthValue(), ColumnBindingMaxLen-2);
return RowBinding.PtrToStringUni(ValueOffset, byteCount / 2);
}
private void Value_WSTR(String value) {
Debug.Assert(null != value, "Value_BYTES null");
Debug.Assert(NativeDBType.WSTR == DbType, "Value_WSTR");
// we silently truncate when the user has specified a given Size
int charCount = ((ValueBindingOffset < value.Length) ? Math.Min(value.Length - ValueBindingOffset, (ColumnBindingMaxLen-2)/2) : 0); // 70232
LengthValue(charCount*2);
StatusValue(DBStatus.S_OK);
if (0 < charCount) {
char[] chars = value.ToCharArray(ValueBindingOffset, charCount);
RowBinding.WriteCharArray(ValueOffset, chars, ValueBindingOffset, charCount);
}
}
private void Value_WSTR(char[] value) {
Debug.Assert(null != value, "Value_BYTES null");
Debug.Assert(NativeDBType.WSTR == DbType, "Value_WSTR");
// we silently truncate when the user has specified a given Size
int charCount = ((ValueBindingOffset < value.Length) ? Math.Min(value.Length - ValueBindingOffset, (ColumnBindingMaxLen-2)/2) : 0); // 70232
LengthValue(charCount*2);
StatusValue(DBStatus.S_OK);
if (0 < charCount) {
RowBinding.WriteCharArray(ValueOffset, value, ValueBindingOffset, charCount);
}
}
private object Value_VARIANT() {
Debug.Assert((NativeDBType.VARIANT == DbType) || (NativeDBType.PROPVARIANT == DbType), "Value_VARIANT");
Debug.Assert(DBStatus.S_OK == StatusValue(), "Value_VARIANT");
return RowBinding.GetVariantValue(ValueOffset);
}
private void Value_VARIANT(object value) {
Debug.Assert((NativeDBType.VARIANT == DbType) || (NativeDBType.PROPVARIANT == DbType), "Value_VARIANT");
LengthValue(0);
StatusValue(DBStatus.S_OK);
RowBinding.SetVariantValue(ValueOffset, value);
}
internal Boolean ValueBoolean() {
Boolean value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.BOOL:
value = Value_BOOL();
break;
case NativeDBType.VARIANT:
value = (Boolean) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Boolean));
}
return value;
}
internal byte[] ValueByteArray() {
byte[] value = (byte[]) _value;
if (null == value) {
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.BYTES:
value = Value_BYTES(); // String
break;
case NativeDBType.VARIANT:
value = (byte[])ValueVariant(); // Object
break;
case (NativeDBType.BYREF | NativeDBType.BYTES):
value = Value_ByRefBYTES();
break;
default:
throw ODB.ConversionRequired();
}
break;
case DBStatus.S_TRUNCATED:
switch(DbType) {
case NativeDBType.BYTES:
value = Value_BYTES();
break;
case (NativeDBType.BYREF | NativeDBType.BYTES):
value = Value_ByRefBYTES();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(byte[]));
}
_value = value;
}
return value;
}
internal Byte ValueByte() {
Byte value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.UI1:
value = Value_UI1();
break;
case NativeDBType.VARIANT:
value = (Byte) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Byte));
}
return value;
}
internal OleDbDataReader ValueChapter() {
OleDbDataReader value = (OleDbDataReader) _value;
if (null == value) {
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.HCHAPTER:
value = Value_HCHAPTER(); // OleDbDataReader
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(String));
}
_value = value;
}
return value;
}
internal DateTime ValueDateTime() {
DateTime value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.DATE:
value = Value_DATE();
break;
case NativeDBType.DBDATE:
value = Value_DBDATE();
break;
case NativeDBType.DBTIMESTAMP:
value = Value_DBTIMESTAMP();
break;
case NativeDBType.FILETIME:
value = Value_FILETIME();
break;
case NativeDBType.VARIANT:
value = (DateTime) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int16));
}
return value;
}
internal Decimal ValueDecimal() {
Decimal value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.CY:
value = Value_CY();
break;
case NativeDBType.DECIMAL:
value = Value_DECIMAL();
break;
case NativeDBType.NUMERIC:
value = Value_NUMERIC();
break;
case NativeDBType.UI8:
value = (Decimal)Value_UI8();
break;
case NativeDBType.VARIANT:
value = (Decimal) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int16));
}
return value;
}
internal Guid ValueGuid() {
Guid value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.GUID:
value = Value_GUID();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int16));
}
return value;
}
internal Int16 ValueInt16() {
Int16 value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.I2:
value = Value_I2();
break;
case NativeDBType.I1:
value = (Int16) Value_I1();
break;
case NativeDBType.VARIANT:
object variant = ValueVariant();
if (variant is SByte) {
value = (Int16)(SByte) variant;
}
else {
value = (Int16) variant;
}
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int16));
}
return value;
}
internal Int32 ValueInt32() {
Int32 value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.I4:
value = Value_I4();
break;
case NativeDBType.UI2:
value = (Int32) Value_UI2();
break;
case NativeDBType.VARIANT:
object variant = ValueVariant();
if (variant is UInt16) {
value = (Int32)(UInt16) variant;
}
else {
value = (Int32) variant;
}
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int32));
}
return value;
}
internal Int64 ValueInt64() {
Int64 value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.I8:
value = Value_I8();
break;
case NativeDBType.UI4:
value = (Int64) Value_UI4();
break;
case NativeDBType.VARIANT:
object variant = ValueVariant();
if (variant is UInt32) {
value = (Int64)(UInt32) variant;
}
else {
value = (Int64) variant;
}
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Int64));
}
return value;
}
internal Single ValueSingle() {
Single value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.R4:
value = Value_R4();
break;
case NativeDBType.VARIANT:
value = (Single) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Single));
}
return value;
}
internal Double ValueDouble() {
Double value;
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.R8:
value = Value_R8();
break;
case NativeDBType.VARIANT:
value = (Double) ValueVariant();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(Double));
}
return value;
}
internal string ValueString() {
string value = (String) _value;
if (null == value) {
switch(StatusValue()) {
case DBStatus.S_OK:
switch(DbType) {
case NativeDBType.BSTR:
value = Value_BSTR(); // String
break;
case NativeDBType.VARIANT:
value = (String) ValueVariant(); // Object
break;
case NativeDBType.WSTR:
value = Value_WSTR(); // String
break;
case (NativeDBType.BYREF | NativeDBType.WSTR):
value = Value_ByRefWSTR();
break;
default:
throw ODB.ConversionRequired();
}
break;
case DBStatus.S_TRUNCATED:
switch(DbType) {
case NativeDBType.WSTR:
value = Value_WSTR();
break;
case (NativeDBType.BYREF | NativeDBType.WSTR):
value = Value_ByRefWSTR();
break;
default:
throw ODB.ConversionRequired();
}
break;
default:
throw CheckTypeValueStatusValue(typeof(String));
}
_value = value;
}
return value;
}
private object ValueVariant() {
object value = _value;
if (null == value) {
value = Value_VARIANT();
_value = value;
}
return value;
}
private Exception CheckTypeValueStatusValue() { // MDAC 71644
return CheckTypeValueStatusValue(ExpectedType);
}
private Exception CheckTypeValueStatusValue(Type expectedType) { // MDAC 71644
switch (StatusValue()) {
case DBStatus.S_OK:
Debug.Assert(false, "CheckStatusValue: unhandled data with ok status");
goto case DBStatus.E_CANTCONVERTVALUE;
case DBStatus.S_TRUNCATED:
Debug.Assert(false, "CheckStatusValue: unhandled data with truncated status");
goto case DBStatus.E_CANTCONVERTVALUE;
case DBStatus.E_BADACCESSOR:
return ODB.BadAccessor();
case DBStatus.E_CANTCONVERTVALUE:
return ODB.CantConvertValue(); //
case DBStatus.S_ISNULL: // database null
return ADP.InvalidCast(); //
case DBStatus.E_SIGNMISMATCH:
return ODB.SignMismatch(expectedType);
case DBStatus.E_DATAOVERFLOW:
return ODB.DataOverflow(expectedType);
case DBStatus.E_CANTCREATE:
return ODB.CantCreate(expectedType);
case DBStatus.E_UNAVAILABLE:
return ODB.Unavailable(expectedType);
default:
return ODB.UnexpectedStatusValue(StatusValue());
}
}
}
}
|