DataContainer.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  1. //
  2. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Collections;
  25. namespace System.Data.Common
  26. {
  27. internal abstract class AbstractDataContainer
  28. {
  29. #region Fields
  30. BitArray _nullValues;
  31. System.Type _type;
  32. DataColumn _column;
  33. #endregion //Fields
  34. #region Properties
  35. internal abstract object this[int index] {
  36. get;
  37. set;
  38. }
  39. internal virtual int Capacity {
  40. get {
  41. return (_nullValues != null) ? _nullValues.Count : 0;
  42. }
  43. set {
  44. if (_nullValues == null) {
  45. _nullValues = new BitArray(value);
  46. }
  47. else {
  48. _nullValues.Length = value;
  49. }
  50. }
  51. }
  52. internal Type Type {
  53. get {
  54. return _type;
  55. }
  56. }
  57. protected DataColumn Column {
  58. get {
  59. return _column;
  60. }
  61. }
  62. #endregion //Properties
  63. #region Methods
  64. internal static AbstractDataContainer CreateInstance(Type type, DataColumn column)
  65. {
  66. AbstractDataContainer container;
  67. switch (Type.GetTypeCode(type)) {
  68. case TypeCode.Int16 :
  69. container = new Int16DataContainer();
  70. break;
  71. case TypeCode.Int32 :
  72. container = new Int32DataContainer();
  73. break;
  74. case TypeCode.Int64 :
  75. container = new Int64DataContainer();
  76. break;
  77. case TypeCode.String :
  78. container = new StringDataContainer();
  79. break;
  80. case TypeCode.Boolean:
  81. container = new BitDataContainer();
  82. break;
  83. case TypeCode.Byte :
  84. container = new ByteDataContainer();
  85. break;
  86. case TypeCode.Char :
  87. container = new CharDataContainer();
  88. break;
  89. case TypeCode.Double :
  90. container = new DoubleDataContainer();
  91. break;
  92. case TypeCode.SByte :
  93. container = new SByteDataContainer();
  94. break;
  95. case TypeCode.Single :
  96. container = new SingleDataContainer();
  97. break;
  98. case TypeCode.UInt16 :
  99. container = new UInt16DataContainer();
  100. break;
  101. case TypeCode.UInt32 :
  102. container = new UInt32DataContainer();
  103. break;
  104. case TypeCode.UInt64 :
  105. container = new UInt64DataContainer();
  106. break;
  107. case TypeCode.DateTime :
  108. container = new DateTimeDataContainer();
  109. break;
  110. case TypeCode.Decimal :
  111. container = new DecimalDataContainer();
  112. break;
  113. default :
  114. container = new ObjectDataContainer();
  115. break;
  116. }
  117. container._type = type;
  118. container._column = column;
  119. return container;
  120. }
  121. internal bool IsNull(int index)
  122. {
  123. return (_nullValues != null) ? _nullValues[index] : true;
  124. }
  125. internal void SetNullBit(int index,bool isNull)
  126. {
  127. _nullValues[index] = isNull;
  128. }
  129. protected void SetNull(int index,bool isNull,bool isDbNull)
  130. {
  131. SetNullBit(index,isDbNull);
  132. // this method must be called after setting the value into value array
  133. // otherwise the dafault value will be overriden
  134. if ( isNull ) {
  135. // set the value to default
  136. CopyValue(Column.Table.DefaultValuesRowIndex,index);
  137. }
  138. }
  139. internal void FillValues(int fromIndex)
  140. {
  141. for(int i=0; i < Capacity; i++) {
  142. CopyValue(fromIndex,i);
  143. _nullValues[i] = _nullValues[fromIndex];
  144. }
  145. }
  146. internal virtual void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  147. {
  148. _nullValues[toIndex] = fromContainer._nullValues[fromIndex];
  149. }
  150. internal virtual void CopyValue(int fromIndex, int toIndex)
  151. {
  152. _nullValues[toIndex] = _nullValues[fromIndex];
  153. }
  154. internal virtual void SetItemFromDataRecord(int index, IDataRecord record, int field)
  155. {
  156. bool isDbNull = record.IsDBNull(field);
  157. SetNull(index,false,isDbNull);
  158. }
  159. protected int CompareNulls(int index1, int index2)
  160. {
  161. bool null1 = IsNull(index1);
  162. bool null2 = IsNull(index2);
  163. if ( null1 ^ null2 ) {
  164. return null1 ? -1 : 1;
  165. }
  166. else {
  167. return 0;
  168. }
  169. }
  170. internal abstract int CompareValues(int index1, int index2);
  171. internal abstract long GetInt64(int index);
  172. #endregion //Methods
  173. sealed class Int16DataContainer : AbstractDataContainer
  174. {
  175. #region Fields
  176. short[] _values;
  177. #endregion //Fields
  178. #region Properties
  179. internal override object this[int index] {
  180. get {
  181. if (IsNull(index)) {
  182. return DBNull.Value;
  183. }
  184. else {
  185. return _values[index];
  186. }
  187. }
  188. set {
  189. bool isDbNull = (value == DBNull.Value);
  190. if (value == null || isDbNull) {
  191. SetValue(index,0);
  192. }
  193. else if( value is short ) {
  194. SetValue(index,(short)value);
  195. }
  196. else {
  197. SetValue(index,Convert.ToInt16(value));
  198. }
  199. SetNull(index,value == null,isDbNull);
  200. }
  201. }
  202. internal override int Capacity {
  203. set {
  204. base.Capacity = value;
  205. if (_values == null) {
  206. _values = new short[value];
  207. }
  208. else {
  209. short[] tmp = new short[value];
  210. Array.Copy(_values,0,tmp,0,_values.Length);
  211. _values = tmp;
  212. }
  213. }
  214. }
  215. #endregion //Properties
  216. #region Methods
  217. private void SetValue(int index, short value)
  218. {
  219. _values[index] = value;
  220. }
  221. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  222. {
  223. // if exception thrown, it should be caught in the caller method
  224. if (record is ISafeDataRecord) {
  225. SetValue(index,((ISafeDataRecord)record).GetInt16Safe(field));
  226. }
  227. else {
  228. this[index] = record.GetValue(field);
  229. }
  230. base.SetItemFromDataRecord(index,record,field);
  231. }
  232. internal override void CopyValue(int fromIndex, int toIndex)
  233. {
  234. base.CopyValue(fromIndex, toIndex);
  235. _values[toIndex] = _values[fromIndex];
  236. }
  237. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  238. {
  239. base.CopyValue(fromContainer, fromIndex, toIndex);
  240. _values[toIndex] = ((Int16DataContainer)fromContainer)._values[fromIndex];
  241. }
  242. internal override int CompareValues(int index1, int index2)
  243. {
  244. short s1 = _values[index1];
  245. short s2 = _values[index2];
  246. if ( s1 == 0 || s2 == 0 ) {
  247. int cn = CompareNulls(index1, index2);
  248. if (cn != 0)
  249. return cn;
  250. }
  251. return s1 - s2;
  252. }
  253. internal override long GetInt64(int index)
  254. {
  255. return (long) _values[index];
  256. }
  257. #endregion //Methods
  258. }
  259. sealed class Int32DataContainer : AbstractDataContainer
  260. {
  261. #region Fields
  262. int[] _values;
  263. #endregion //Fields
  264. #region Properties
  265. internal override object this[int index] {
  266. get {
  267. if (IsNull(index)) {
  268. return DBNull.Value;
  269. }
  270. else {
  271. return _values[index];
  272. }
  273. }
  274. set {
  275. bool isDbNull = (value == DBNull.Value);
  276. if (value == null || isDbNull) {
  277. SetValue(index,0);
  278. }
  279. else if( value is int ) {
  280. SetValue(index,(int)value);
  281. }
  282. else {
  283. SetValue(index,Convert.ToInt32(value));
  284. }
  285. SetNull(index,value == null,isDbNull);
  286. }
  287. }
  288. internal override int Capacity {
  289. set {
  290. base.Capacity = value;
  291. if (_values == null) {
  292. _values = new int[value];
  293. }
  294. else {
  295. int[] tmp = new int[value];
  296. Array.Copy(_values,0,tmp,0,_values.Length);
  297. _values = tmp;
  298. }
  299. }
  300. }
  301. #endregion //Properties
  302. #region Methods
  303. private void SetValue(int index, int value)
  304. {
  305. _values[index] = value;
  306. }
  307. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  308. {
  309. // if exception thrown, it should be caught in the caller method
  310. if (record is ISafeDataRecord) {
  311. SetValue(index,((ISafeDataRecord)record).GetInt32Safe(field));
  312. }
  313. else {
  314. this[index] = record.GetValue(field);
  315. }
  316. base.SetItemFromDataRecord(index,record,field);
  317. }
  318. internal override void CopyValue(int fromIndex, int toIndex)
  319. {
  320. base.CopyValue(fromIndex, toIndex);
  321. _values[toIndex] = _values[fromIndex];
  322. }
  323. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  324. {
  325. base.CopyValue(fromContainer, fromIndex, toIndex);
  326. _values[toIndex] = ((Int32DataContainer)fromContainer)._values[fromIndex];
  327. }
  328. internal override int CompareValues(int index1, int index2)
  329. {
  330. int i1 = _values[index1];
  331. int i2 = _values[index2];
  332. if (i1 == 0 || i2 == 0) {
  333. int cn = CompareNulls(index1, index2);
  334. if (cn != 0)
  335. return cn;
  336. }
  337. if ( i1 <= i2 ) {
  338. return ( i1 == i2 ) ? 0 : -1;
  339. }
  340. return 1;
  341. }
  342. internal override long GetInt64(int index)
  343. {
  344. return (long) _values[index];
  345. }
  346. #endregion //Methods
  347. }
  348. sealed class Int64DataContainer : AbstractDataContainer
  349. {
  350. #region Fields
  351. long[] _values;
  352. #endregion //Fields
  353. #region Properties
  354. internal override object this[int index] {
  355. get {
  356. if (IsNull(index)) {
  357. return DBNull.Value;
  358. }
  359. else {
  360. return _values[index];
  361. }
  362. }
  363. set {
  364. bool isDbNull = (value == DBNull.Value);
  365. if (value == null || isDbNull) {
  366. SetValue(index,0);
  367. }
  368. else if( value is long ) {
  369. SetValue(index,(long)value);
  370. }
  371. else {
  372. SetValue(index,Convert.ToInt64(value));
  373. }
  374. SetNull(index,value == null,isDbNull);
  375. }
  376. }
  377. internal override int Capacity {
  378. set {
  379. base.Capacity = value;
  380. if (_values == null) {
  381. _values = new long[value];
  382. }
  383. else {
  384. long[] tmp = new long[value];
  385. Array.Copy(_values,0,tmp,0,_values.Length);
  386. _values = tmp;
  387. }
  388. }
  389. }
  390. #endregion //Properties
  391. #region Methods
  392. private void SetValue(int index, long value)
  393. {
  394. _values[index] = value;
  395. }
  396. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  397. {
  398. // if exception thrown, it should be caught in the caller method
  399. if (record is ISafeDataRecord) {
  400. SetValue(index,((ISafeDataRecord)record).GetInt64Safe(field));
  401. }
  402. else {
  403. this[index] = record.GetValue(field);
  404. }
  405. base.SetItemFromDataRecord(index,record,field);
  406. }
  407. internal override void CopyValue(int fromIndex, int toIndex)
  408. {
  409. base.CopyValue(fromIndex, toIndex);
  410. _values[toIndex] = _values[fromIndex];
  411. }
  412. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  413. {
  414. base.CopyValue(fromContainer, fromIndex, toIndex);
  415. _values[toIndex] = ((Int64DataContainer)fromContainer)._values[fromIndex];
  416. }
  417. internal override int CompareValues(int index1, int index2)
  418. {
  419. long l1 = _values[index1];
  420. long l2 = _values[index2];
  421. if ( l1 == 0 || l2 == 0 ) {
  422. int cn = CompareNulls(index1, index2);
  423. if (cn != 0) {
  424. return cn;
  425. }
  426. }
  427. if ( l1 <= l2 ) {
  428. return ( l1 != l2 ) ? -1 : 0;
  429. }
  430. return 1;
  431. }
  432. internal override long GetInt64(int index)
  433. {
  434. return _values[index];
  435. }
  436. #endregion //Methods
  437. }
  438. sealed class SingleDataContainer : AbstractDataContainer
  439. {
  440. #region Fields
  441. float[] _values;
  442. #endregion //Fields
  443. #region Properties
  444. internal override object this[int index] {
  445. get {
  446. if (IsNull(index)) {
  447. return DBNull.Value;
  448. }
  449. else {
  450. return _values[index];
  451. }
  452. }
  453. set {
  454. bool isDbNull = (value == DBNull.Value);
  455. if (value == null || isDbNull) {
  456. SetValue(index,0);
  457. }
  458. else if( value is float ) {
  459. SetValue(index,(float)value);
  460. }
  461. else {
  462. SetValue(index,Convert.ToSingle(value));
  463. }
  464. SetNull(index,value == null,isDbNull);
  465. }
  466. }
  467. internal override int Capacity {
  468. set {
  469. base.Capacity = value;
  470. if (_values == null) {
  471. _values = new float[value];
  472. }
  473. else {
  474. float[] tmp = new float[value];
  475. Array.Copy(_values,0,tmp,0,_values.Length);
  476. _values = tmp;
  477. }
  478. }
  479. }
  480. #endregion //Properties
  481. #region Methods
  482. private void SetValue(int index, float value)
  483. {
  484. _values[index] = value;
  485. }
  486. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  487. {
  488. // if exception thrown, it should be caught in the caller method
  489. if (record is ISafeDataRecord) {
  490. SetValue(index,((ISafeDataRecord)record).GetFloatSafe(field));
  491. }
  492. else {
  493. this[index] = record.GetValue(field);
  494. }
  495. base.SetItemFromDataRecord(index,record,field);
  496. }
  497. internal override void CopyValue(int fromIndex, int toIndex)
  498. {
  499. base.CopyValue(fromIndex, toIndex);
  500. _values[toIndex] = _values[fromIndex];
  501. }
  502. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  503. {
  504. base.CopyValue(fromContainer, fromIndex, toIndex);
  505. _values[toIndex] = ((SingleDataContainer)fromContainer)._values[fromIndex];
  506. }
  507. internal override int CompareValues(int index1, int index2)
  508. {
  509. float f1 = _values[index1];
  510. float f2 = _values[index2];
  511. if ( f1 == 0 || f2 == 0 ) {
  512. int cn = CompareNulls(index1, index2);
  513. if (cn != 0) {
  514. return cn;
  515. }
  516. }
  517. if ( f1 <= f2 ) {
  518. return ( f1 != f2 ) ? -1 : 0;
  519. }
  520. return 1;
  521. }
  522. internal override long GetInt64(int index)
  523. {
  524. return Convert.ToInt64(_values[index]);
  525. }
  526. #endregion //Methods
  527. }
  528. sealed class DoubleDataContainer : AbstractDataContainer
  529. {
  530. #region Fields
  531. double[] _values;
  532. #endregion //Fields
  533. #region Properties
  534. internal override object this[int index] {
  535. get {
  536. if (IsNull(index)) {
  537. return DBNull.Value;
  538. }
  539. else {
  540. return _values[index];
  541. }
  542. }
  543. set {
  544. bool isDbNull = (value == DBNull.Value);
  545. if (value == null || isDbNull) {
  546. SetValue(index,0);
  547. }
  548. else if( value is double ) {
  549. SetValue(index,(double)value);
  550. }
  551. else {
  552. SetValue(index,Convert.ToDouble(value));
  553. }
  554. SetNull(index,value == null,isDbNull);
  555. }
  556. }
  557. internal override int Capacity {
  558. set {
  559. base.Capacity = value;
  560. if (_values == null) {
  561. _values = new double[value];
  562. }
  563. else {
  564. double[] tmp = new double[value];
  565. Array.Copy(_values,0,tmp,0,_values.Length);
  566. _values = tmp;
  567. }
  568. }
  569. }
  570. #endregion //Properties
  571. #region Methods
  572. private void SetValue(int index, double value)
  573. {
  574. _values[index] = value;
  575. }
  576. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  577. {
  578. // if exception thrown, it should be caught in the caller method
  579. if (record is ISafeDataRecord) {
  580. SetValue(index,((ISafeDataRecord)record).GetDoubleSafe(field));
  581. }
  582. else {
  583. this[index] = record.GetValue(field);
  584. }
  585. base.SetItemFromDataRecord(index,record,field);
  586. }
  587. internal override void CopyValue(int fromIndex, int toIndex)
  588. {
  589. base.CopyValue(fromIndex, toIndex);
  590. _values[toIndex] = _values[fromIndex];
  591. }
  592. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  593. {
  594. base.CopyValue(fromContainer, fromIndex, toIndex);
  595. _values[toIndex] = ((DoubleDataContainer)fromContainer)._values[fromIndex];
  596. }
  597. internal override int CompareValues(int index1, int index2)
  598. {
  599. double d1 = _values[index1];
  600. double d2 = _values[index2];
  601. if ( d1 == 0 || d2 == 0 ) {
  602. int cn = CompareNulls(index1, index2);
  603. if (cn != 0) {
  604. return cn;
  605. }
  606. }
  607. if ( d1 <= d2 ) {
  608. return ( d1 != d2 ) ? -1 : 0;
  609. }
  610. return 1;
  611. }
  612. internal override long GetInt64(int index)
  613. {
  614. return Convert.ToInt64(_values[index]);
  615. }
  616. #endregion //Methods
  617. }
  618. sealed class ByteDataContainer : AbstractDataContainer
  619. {
  620. #region Fields
  621. byte[] _values;
  622. #endregion //Fields
  623. #region Properties
  624. internal override object this[int index] {
  625. get {
  626. if (IsNull(index)) {
  627. return DBNull.Value;
  628. }
  629. else {
  630. return _values[index];
  631. }
  632. }
  633. set {
  634. bool isDbNull = (value == DBNull.Value);
  635. if (value == null || isDbNull) {
  636. SetValue(index,0);
  637. }
  638. else if( value is byte ) {
  639. SetValue(index,(byte)value);
  640. }
  641. else {
  642. SetValue(index,Convert.ToByte(value));
  643. }
  644. SetNull(index,value == null,isDbNull);
  645. }
  646. }
  647. internal override int Capacity {
  648. set {
  649. base.Capacity = value;
  650. if (_values == null) {
  651. _values = new byte[value];
  652. }
  653. else {
  654. byte[] tmp = new byte[value];
  655. Array.Copy(_values,0,tmp,0,_values.Length);
  656. _values = tmp;
  657. }
  658. }
  659. }
  660. #endregion //Properties
  661. #region Methods
  662. private void SetValue(int index, byte value)
  663. {
  664. _values[index] = value;
  665. }
  666. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  667. {
  668. // if exception thrown, it should be caught in the caller method
  669. if (record is ISafeDataRecord) {
  670. SetValue(index,((ISafeDataRecord)record).GetByteSafe(field));
  671. }
  672. else {
  673. this[index] = record.GetValue(field);
  674. }
  675. base.SetItemFromDataRecord(index,record,field);
  676. }
  677. internal override void CopyValue(int fromIndex, int toIndex)
  678. {
  679. base.CopyValue(fromIndex, toIndex);
  680. _values[toIndex] = _values[fromIndex];
  681. }
  682. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  683. {
  684. base.CopyValue(fromContainer, fromIndex, toIndex);
  685. _values[toIndex] = ((ByteDataContainer)fromContainer)._values[fromIndex];
  686. }
  687. internal override int CompareValues(int index1, int index2)
  688. {
  689. byte b1 = _values[index1];
  690. byte b2 = _values[index2];
  691. if ( b1 == 0 || b2 == 0 ) {
  692. int cn = CompareNulls(index1, index2);
  693. if (cn != 0) {
  694. return cn;
  695. }
  696. }
  697. return b1 - b2;
  698. }
  699. internal override long GetInt64(int index)
  700. {
  701. return (long) _values[index];
  702. }
  703. #endregion //Methods
  704. }
  705. sealed class BitDataContainer : AbstractDataContainer
  706. {
  707. #region Fields
  708. bool[] _values;
  709. #endregion //Fields
  710. #region Properties
  711. internal override object this[int index] {
  712. get {
  713. bool isNull = IsNull(index);
  714. if (isNull) {
  715. return DBNull.Value;
  716. }
  717. else {
  718. return _values[index];
  719. }
  720. }
  721. set {
  722. bool isDbNull = (value == DBNull.Value);
  723. if (value == null || isDbNull) {
  724. SetValue(index,false);
  725. }
  726. else if( value is bool ) {
  727. SetValue(index,(bool)value);
  728. }
  729. else {
  730. SetValue(index,Convert.ToBoolean(value));
  731. }
  732. SetNull(index,value == null,isDbNull);
  733. }
  734. }
  735. internal override int Capacity {
  736. set {
  737. base.Capacity = value;
  738. if (_values == null) {
  739. _values = new bool[value];
  740. }
  741. else {
  742. bool[] tmp = new bool[value];
  743. Array.Copy(_values,0,tmp,0,_values.Length);
  744. _values = tmp;
  745. }
  746. }
  747. }
  748. #endregion //Properties
  749. #region Methods
  750. private void SetValue(int index, bool value)
  751. {
  752. _values[index] = value;
  753. }
  754. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  755. {
  756. // if exception thrown, it should be caught in the caller method
  757. if (record is ISafeDataRecord) {
  758. SetValue(index,((ISafeDataRecord)record).GetBooleanSafe(field));
  759. }
  760. else {
  761. this[index] = record.GetValue(field);
  762. }
  763. }
  764. internal override void CopyValue(int fromIndex, int toIndex)
  765. {
  766. base.CopyValue(fromIndex, toIndex);
  767. _values[toIndex] = _values[fromIndex];
  768. }
  769. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  770. {
  771. base.CopyValue(fromContainer, fromIndex, toIndex);
  772. _values[toIndex] = ((BitDataContainer)fromContainer)._values[fromIndex];
  773. }
  774. internal override int CompareValues(int index1, int index2)
  775. {
  776. bool b1 = _values[index1];
  777. bool b2 = _values[index2];
  778. if ( b1 ^ b2 ) {
  779. return b1 ? 1 : -1;
  780. }
  781. if ( b1 ) {
  782. return 0;
  783. }
  784. return CompareNulls(index1, index2);
  785. }
  786. internal override long GetInt64(int index)
  787. {
  788. return Convert.ToInt64(_values[index]);
  789. }
  790. #endregion //Methods
  791. }
  792. abstract class AbstractObjectDataContainer : AbstractDataContainer
  793. {
  794. #region Fields
  795. object[] _values;
  796. #endregion //Fields
  797. #region Properties
  798. internal override object this[int index] {
  799. get {
  800. if (IsNull(index))
  801. return DBNull.Value;
  802. return _values[index];
  803. }
  804. set {
  805. SetValue(index,value);
  806. SetNull(index,value == null,value == DBNull.Value);
  807. }
  808. }
  809. internal override int Capacity {
  810. set {
  811. base.Capacity = value;
  812. if (_values == null) {
  813. _values = new object[value];
  814. }
  815. else {
  816. object[] tmp = new object[value];
  817. Array.Copy(_values,0,tmp,0,_values.Length);
  818. _values = tmp;
  819. }
  820. }
  821. }
  822. #endregion //Properties
  823. #region Methods
  824. protected virtual void SetValue(int index, object value)
  825. {
  826. if(value == null) {
  827. value = Column.DefaultValue;
  828. }
  829. _values[index] = value;
  830. }
  831. internal override void CopyValue(int fromIndex, int toIndex)
  832. {
  833. base.CopyValue(fromIndex, toIndex);
  834. _values[toIndex] = _values[fromIndex];
  835. }
  836. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  837. {
  838. base.CopyValue(fromContainer, fromIndex, toIndex);
  839. _values[toIndex] = ((AbstractObjectDataContainer)fromContainer)._values[fromIndex];
  840. }
  841. internal override int CompareValues(int index1, int index2)
  842. {
  843. object obj1 = _values[index1];
  844. object obj2 = _values[index2];
  845. if(obj1 == obj2)
  846. {
  847. return 0;
  848. }
  849. else
  850. {
  851. int cn = CompareNulls(index1, index2);
  852. if (cn != 0)
  853. return cn;
  854. if (obj1 is IComparable)
  855. {
  856. try
  857. {
  858. return ((IComparable)obj1).CompareTo(obj2);
  859. }
  860. catch
  861. {
  862. //just suppress
  863. }
  864. if (obj2 is IComparable)
  865. {
  866. obj2 = Convert.ChangeType(obj2, Type.GetTypeCode(obj1.GetType()));
  867. return ((IComparable)obj1).CompareTo(obj2);
  868. }
  869. }
  870. }
  871. return String.Compare(obj1.ToString(), obj2.ToString());
  872. }
  873. internal override long GetInt64(int index)
  874. {
  875. return Convert.ToInt64(_values[index]);
  876. }
  877. #endregion //Methods
  878. }
  879. sealed class ObjectDataContainer : AbstractObjectDataContainer
  880. {
  881. #region Methods
  882. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  883. {
  884. // if exception thrown, it should be caught
  885. // in the caller method
  886. SetValue(index,record.GetValue(field));
  887. base.SetItemFromDataRecord(index,record,field);
  888. }
  889. protected override void SetValue(int index, object value)
  890. {
  891. if(value != null && value != DBNull.Value && !Type.IsAssignableFrom(value.GetType()))
  892. value = Convert.ChangeType(value, Type);
  893. base.SetValue(index, value);
  894. }
  895. #endregion //Methods
  896. }
  897. sealed class DateTimeDataContainer : AbstractObjectDataContainer
  898. {
  899. #region Methods
  900. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  901. {
  902. // if exception thrown, it should be caught
  903. // in the caller method
  904. base.SetValue(index,record.GetDateTime(field));
  905. base.SetItemFromDataRecord(index,record,field);
  906. }
  907. protected override void SetValue(int index, object value)
  908. {
  909. if (value != null && value != DBNull.Value)
  910. value = Convert.ToDateTime(value);
  911. base.SetValue(index, value);
  912. }
  913. #endregion //Methods
  914. }
  915. sealed class DecimalDataContainer : AbstractObjectDataContainer
  916. {
  917. #region Methods
  918. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  919. {
  920. // if exception thrown, it should be caught in the caller method
  921. if (record is ISafeDataRecord) {
  922. SetValue(index,((ISafeDataRecord)record).GetDecimalSafe(field));
  923. }
  924. else {
  925. this[index] = record.GetValue(field);
  926. }
  927. base.SetItemFromDataRecord(index,record,field);
  928. }
  929. protected override void SetValue(int index, object value)
  930. {
  931. if (value != null && value != DBNull.Value)
  932. value = Convert.ToDecimal(value);
  933. base.SetValue(index, value);
  934. }
  935. #endregion //Methods
  936. }
  937. sealed class StringDataContainer : AbstractObjectDataContainer
  938. {
  939. #region Methods
  940. private void SetValue(int index, string value)
  941. {
  942. if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {
  943. throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");
  944. }
  945. base.SetValue(index,value);
  946. }
  947. protected override void SetValue(int index, object value)
  948. {
  949. if ( value != null && value != DBNull.Value ) {
  950. if ( value is string ) {
  951. SetValue(index, (string) value);
  952. }
  953. else {
  954. SetValue(index, Convert.ToString(value));
  955. }
  956. return;
  957. }
  958. base.SetValue(index, value);
  959. }
  960. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  961. {
  962. // if exception thrown, it should be caught
  963. // in the caller method
  964. if (record is ISafeDataRecord) {
  965. SetValue(index,((ISafeDataRecord)record).GetStringSafe(field));
  966. }
  967. else {
  968. this[index] = record.GetValue(field);
  969. }
  970. base.SetItemFromDataRecord(index,record,field);
  971. }
  972. internal override int CompareValues(int index1, int index2)
  973. {
  974. bool isNull1 = IsNull(index1);
  975. bool isNull2 = IsNull(index2);
  976. if (isNull1) {
  977. return isNull2 ? 0 : -1;
  978. }
  979. else {
  980. if (isNull2) {
  981. return 1;
  982. }
  983. }
  984. return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive);
  985. }
  986. #endregion //Methods
  987. }
  988. sealed class CharDataContainer : AbstractDataContainer
  989. {
  990. #region Fields
  991. char[] _values;
  992. #endregion //Fields
  993. #region Properties
  994. internal override object this[int index] {
  995. get {
  996. if (IsNull(index)) {
  997. return DBNull.Value;
  998. }
  999. else {
  1000. return _values[index];
  1001. }
  1002. }
  1003. set {
  1004. bool isDbNull = (value == DBNull.Value);
  1005. if (value == null || isDbNull) {
  1006. SetValue(index,'\0');
  1007. }
  1008. else if( value is char ) {
  1009. SetValue(index,(char)value);
  1010. }
  1011. else {
  1012. SetValue(index,Convert.ToChar(value));
  1013. }
  1014. SetNull(index,value == null,isDbNull);
  1015. }
  1016. }
  1017. internal override int Capacity {
  1018. set {
  1019. base.Capacity = value;
  1020. if (_values == null) {
  1021. _values = new char[value];
  1022. }
  1023. else {
  1024. char[] tmp = new char[value];
  1025. Array.Copy(_values,0,tmp,0,_values.Length);
  1026. _values = tmp;
  1027. }
  1028. }
  1029. }
  1030. #endregion //Properties
  1031. #region Methods
  1032. private void SetValue(int index, char value)
  1033. {
  1034. _values[index] = value;
  1035. }
  1036. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1037. {
  1038. // if exception thrown, it should be caught in the caller method
  1039. if (record is ISafeDataRecord) {
  1040. SetValue(index,((ISafeDataRecord)record).GetCharSafe(field));
  1041. }
  1042. else {
  1043. this[index] = record.GetValue(field);
  1044. }
  1045. base.SetItemFromDataRecord(index,record,field);
  1046. }
  1047. internal override void CopyValue(int fromIndex, int toIndex)
  1048. {
  1049. base.CopyValue(fromIndex, toIndex);
  1050. _values[toIndex] = _values[fromIndex];
  1051. }
  1052. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1053. {
  1054. base.CopyValue(fromContainer, fromIndex, toIndex);
  1055. _values[toIndex] = ((CharDataContainer)fromContainer)._values[fromIndex];
  1056. }
  1057. internal override int CompareValues(int index1, int index2)
  1058. {
  1059. char c1 = _values[index1];
  1060. char c2 = _values[index2];
  1061. if ( c1 == '\0' || c2 == '\0' )
  1062. {
  1063. int cn = CompareNulls(index1, index2);
  1064. if (cn != 0)
  1065. return cn;
  1066. }
  1067. return c1 - c2;
  1068. }
  1069. internal override long GetInt64(int index)
  1070. {
  1071. return Convert.ToInt64(_values[index]);
  1072. }
  1073. #endregion //Methods
  1074. }
  1075. sealed class UInt16DataContainer : AbstractDataContainer
  1076. {
  1077. #region Fields
  1078. ushort[] _values;
  1079. #endregion //Fields
  1080. #region Properties
  1081. internal override object this[int index] {
  1082. get {
  1083. if (IsNull(index)) {
  1084. return DBNull.Value;
  1085. }
  1086. else {
  1087. return _values[index];
  1088. }
  1089. }
  1090. set {
  1091. bool isDbNull = (value == DBNull.Value);
  1092. if (value == null || isDbNull) {
  1093. SetValue(index,0);
  1094. }
  1095. else if( value is ushort ) {
  1096. SetValue(index,(ushort)value);
  1097. }
  1098. else {
  1099. SetValue(index,Convert.ToUInt16(value));
  1100. }
  1101. SetNull(index,value == null,isDbNull);
  1102. }
  1103. }
  1104. internal override int Capacity {
  1105. set {
  1106. base.Capacity = value;
  1107. if (_values == null) {
  1108. _values = new ushort[value];
  1109. }
  1110. else {
  1111. ushort[] tmp = new ushort[value];
  1112. Array.Copy(_values,0,tmp,0,_values.Length);
  1113. _values = tmp;
  1114. }
  1115. }
  1116. }
  1117. #endregion //Properties
  1118. #region Methods
  1119. private void SetValue(int index, ushort value)
  1120. {
  1121. _values[index] = value;
  1122. }
  1123. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1124. {
  1125. // if exception thrown, it should be caught in the caller method
  1126. if (record is ISafeDataRecord) {
  1127. SetValue(index,(ushort)((ISafeDataRecord)record).GetInt16Safe(field));
  1128. }
  1129. else {
  1130. this[index] = record.GetValue(field);
  1131. }
  1132. base.SetItemFromDataRecord(index,record,field);
  1133. }
  1134. internal override void CopyValue(int fromIndex, int toIndex)
  1135. {
  1136. base.CopyValue(fromIndex, toIndex);
  1137. _values[toIndex] = _values[fromIndex];
  1138. }
  1139. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1140. {
  1141. base.CopyValue(fromContainer, fromIndex, toIndex);
  1142. _values[toIndex] = ((UInt16DataContainer)fromContainer)._values[fromIndex];
  1143. }
  1144. internal override int CompareValues(int index1, int index2)
  1145. {
  1146. ushort s1 = _values[index1];
  1147. ushort s2 = _values[index2];
  1148. if ( s1 == 0 || s2 == 0 ) {
  1149. int cn = CompareNulls(index1, index2);
  1150. if (cn != 0)
  1151. return cn;
  1152. }
  1153. return s1 - s2;
  1154. }
  1155. internal override long GetInt64(int index)
  1156. {
  1157. return Convert.ToInt64(_values[index]);
  1158. }
  1159. #endregion //Methods
  1160. }
  1161. sealed class UInt32DataContainer : AbstractDataContainer
  1162. {
  1163. #region Fields
  1164. uint[] _values;
  1165. #endregion //Fields
  1166. #region Properties
  1167. internal override object this[int index] {
  1168. get {
  1169. if (IsNull(index)) {
  1170. return DBNull.Value;
  1171. }
  1172. else {
  1173. return _values[index];
  1174. }
  1175. }
  1176. set {
  1177. bool isDbNull = (value == DBNull.Value);
  1178. if (value == null || isDbNull) {
  1179. SetValue(index,0);
  1180. }
  1181. else if( value is uint ) {
  1182. SetValue(index,(uint)value);
  1183. }
  1184. else {
  1185. SetValue(index,Convert.ToUInt32(value));
  1186. }
  1187. SetNull(index,value == null,isDbNull);
  1188. }
  1189. }
  1190. internal override int Capacity {
  1191. set {
  1192. base.Capacity = value;
  1193. if (_values == null) {
  1194. _values = new uint[value];
  1195. }
  1196. else {
  1197. uint[] tmp = new uint[value];
  1198. Array.Copy(_values,0,tmp,0,_values.Length);
  1199. _values = tmp;
  1200. }
  1201. }
  1202. }
  1203. #endregion //Properties
  1204. #region Methods
  1205. private void SetValue(int index, uint value)
  1206. {
  1207. _values[index] = value;
  1208. }
  1209. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1210. {
  1211. // if exception thrown, it should be caught in the caller method
  1212. if (record is ISafeDataRecord) {
  1213. SetValue(index,(uint)((ISafeDataRecord)record).GetInt32Safe(field));
  1214. }
  1215. else {
  1216. this[index] = record.GetValue(field);
  1217. }
  1218. base.SetItemFromDataRecord(index,record,field);
  1219. }
  1220. internal override void CopyValue(int fromIndex, int toIndex)
  1221. {
  1222. base.CopyValue(fromIndex, toIndex);
  1223. _values[toIndex] = _values[fromIndex];
  1224. }
  1225. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1226. {
  1227. base.CopyValue(fromContainer, fromIndex, toIndex);
  1228. _values[toIndex] = ((UInt32DataContainer)fromContainer)._values[fromIndex];
  1229. }
  1230. internal override int CompareValues(int index1, int index2)
  1231. {
  1232. uint i1 = _values[index1];
  1233. uint i2 = _values[index2];
  1234. if ( i1 == 0 || i2 == 0 ) {
  1235. int cn = CompareNulls(index1, index2);
  1236. if (cn != 0)
  1237. return cn;
  1238. }
  1239. if ( i1 <= i2 ) {
  1240. return ( i1 != i2 ) ? -1 : 0;
  1241. }
  1242. return 1;
  1243. }
  1244. internal override long GetInt64(int index)
  1245. {
  1246. return Convert.ToInt64(_values[index]);
  1247. }
  1248. #endregion //Methods
  1249. }
  1250. sealed class UInt64DataContainer : AbstractDataContainer
  1251. {
  1252. #region Fields
  1253. ulong[] _values;
  1254. #endregion //Fields
  1255. #region Properties
  1256. internal override object this[int index] {
  1257. get {
  1258. if (IsNull(index)) {
  1259. return DBNull.Value;
  1260. }
  1261. else {
  1262. return _values[index];
  1263. }
  1264. }
  1265. set {
  1266. bool isDbNull = (value == DBNull.Value);
  1267. if (value == null || isDbNull) {
  1268. SetValue(index,0);
  1269. }
  1270. else if( value is ulong ) {
  1271. SetValue(index,(ulong)value);
  1272. }
  1273. else {
  1274. SetValue(index,Convert.ToUInt64(value));
  1275. }
  1276. SetNull(index,value == null,isDbNull);
  1277. }
  1278. }
  1279. internal override int Capacity {
  1280. set {
  1281. base.Capacity = value;
  1282. if (_values == null) {
  1283. _values = new ulong[value];
  1284. }
  1285. else {
  1286. ulong[] tmp = new ulong[value];
  1287. Array.Copy(_values,0,tmp,0,_values.Length);
  1288. _values = tmp;
  1289. }
  1290. }
  1291. }
  1292. #endregion //Properties
  1293. #region Methods
  1294. private void SetValue(int index, ulong value)
  1295. {
  1296. _values[index] = value;
  1297. }
  1298. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1299. {
  1300. // if exception thrown, it should be caught in the caller method
  1301. if (record is ISafeDataRecord) {
  1302. SetValue(index,(ulong)((ISafeDataRecord)record).GetInt64Safe(field));
  1303. }
  1304. else {
  1305. this[index] = record.GetValue(field);
  1306. }
  1307. base.SetItemFromDataRecord(index,record,field);
  1308. }
  1309. internal override void CopyValue(int fromIndex, int toIndex)
  1310. {
  1311. base.CopyValue(fromIndex, toIndex);
  1312. _values[toIndex] = _values[fromIndex];
  1313. }
  1314. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1315. {
  1316. base.CopyValue(fromContainer, fromIndex, toIndex);
  1317. _values[toIndex] = ((UInt64DataContainer)fromContainer)._values[fromIndex];
  1318. }
  1319. internal override int CompareValues(int index1, int index2)
  1320. {
  1321. ulong l1 = _values[index1];
  1322. ulong l2 = _values[index2];
  1323. if ( l1 == 0 || l2 == 0 ) {
  1324. int cn = CompareNulls(index1, index2);
  1325. if (cn != 0) {
  1326. return cn;
  1327. }
  1328. }
  1329. if ( l1 <= l2 ) {
  1330. return ( l1 != l2 ) ? -1 : 0;
  1331. }
  1332. return 1;
  1333. }
  1334. internal override long GetInt64(int index)
  1335. {
  1336. return Convert.ToInt64(_values[index]);
  1337. }
  1338. #endregion //Methods
  1339. }
  1340. sealed class SByteDataContainer : AbstractDataContainer
  1341. {
  1342. #region Fields
  1343. sbyte[] _values;
  1344. #endregion //Fields
  1345. #region Properties
  1346. internal override object this[int index] {
  1347. get {
  1348. if (IsNull(index)) {
  1349. return DBNull.Value;
  1350. }
  1351. else {
  1352. return _values[index];
  1353. }
  1354. }
  1355. set {
  1356. bool isDbNull = (value == DBNull.Value);
  1357. if (value == null || isDbNull) {
  1358. SetValue(index,0);
  1359. }
  1360. else if( value is sbyte ) {
  1361. SetValue(index,(sbyte)value);
  1362. }
  1363. else {
  1364. SetValue(index,Convert.ToSByte(value));
  1365. }
  1366. SetNull(index,value == null,isDbNull);
  1367. }
  1368. }
  1369. internal override int Capacity {
  1370. set {
  1371. base.Capacity = value;
  1372. if (_values == null) {
  1373. _values = new sbyte[value];
  1374. }
  1375. else {
  1376. sbyte[] tmp = new sbyte[value];
  1377. Array.Copy(_values,0,tmp,0,_values.Length);
  1378. _values = tmp;
  1379. }
  1380. }
  1381. }
  1382. #endregion //Properties
  1383. #region Methods
  1384. private void SetValue(int index, sbyte value)
  1385. {
  1386. _values[index] = value;
  1387. }
  1388. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1389. {
  1390. // if exception thrown, it should be caught in the caller method
  1391. if (record is ISafeDataRecord) {
  1392. SetValue(index,(sbyte)((ISafeDataRecord)record).GetByteSafe(field));
  1393. }
  1394. else {
  1395. this[index] = record.GetValue(field);
  1396. }
  1397. base.SetItemFromDataRecord(index,record,field);
  1398. }
  1399. internal override void CopyValue(int fromIndex, int toIndex)
  1400. {
  1401. base.CopyValue(fromIndex, toIndex);
  1402. _values[toIndex] = _values[fromIndex];
  1403. }
  1404. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1405. {
  1406. base.CopyValue(fromContainer, fromIndex, toIndex);
  1407. _values[toIndex] = ((SByteDataContainer)fromContainer)._values[fromIndex];
  1408. }
  1409. internal override int CompareValues(int index1, int index2)
  1410. {
  1411. sbyte b1 = _values[index1];
  1412. sbyte b2 = _values[index2];
  1413. if ( b1 == 0 || b2 == 0 ) {
  1414. int cn = CompareNulls(index1, index2);
  1415. if (cn != 0) {
  1416. return cn;
  1417. }
  1418. }
  1419. return b1 - b2;
  1420. }
  1421. internal override long GetInt64(int index)
  1422. {
  1423. return Convert.ToSByte(_values[index]);
  1424. }
  1425. #endregion //Methods
  1426. }
  1427. }
  1428. }