DataContainer.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  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 abstract void SetItemFromDataRecord(int index, IDataRecord record, int field);
  155. protected int CompareNulls(int index1, int index2)
  156. {
  157. bool null1 = IsNull(index1);
  158. bool null2 = IsNull(index2);
  159. if ( null1 ^ null2 ) {
  160. return null1 ? -1 : 1;
  161. }
  162. else {
  163. return 0;
  164. }
  165. }
  166. internal abstract int CompareValues(int index1, int index2);
  167. internal abstract long GetInt64(int index);
  168. #endregion //Methods
  169. sealed class Int16DataContainer : AbstractDataContainer
  170. {
  171. #region Fields
  172. short[] _values;
  173. #endregion //Fields
  174. #region Properties
  175. internal override object this[int index] {
  176. get {
  177. if (IsNull(index)) {
  178. return DBNull.Value;
  179. }
  180. else {
  181. return _values[index];
  182. }
  183. }
  184. set {
  185. bool isDbNull = (value == DBNull.Value);
  186. if (value == null || isDbNull) {
  187. SetValue(index,0);
  188. }
  189. else if( value is short ) {
  190. SetValue(index,(short)value);
  191. }
  192. else {
  193. SetValue(index,Convert.ToInt16(value));
  194. }
  195. SetNull(index,value == null,isDbNull);
  196. }
  197. }
  198. internal override int Capacity {
  199. set {
  200. base.Capacity = value;
  201. if (_values == null) {
  202. _values = new short[value];
  203. }
  204. else {
  205. short[] tmp = new short[value];
  206. Array.Copy(_values,0,tmp,0,_values.Length);
  207. _values = tmp;
  208. }
  209. }
  210. }
  211. #endregion //Properties
  212. #region Methods
  213. private void SetValue(int index, short value)
  214. {
  215. _values[index] = value;
  216. }
  217. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  218. {
  219. bool isDbNull = record.IsDBNull(field);
  220. if (isDbNull) {
  221. SetNull(index,false,isDbNull);
  222. return;
  223. }
  224. // if exception thrown, it should be caught in the caller method
  225. if (record is ISafeDataRecord) {
  226. SetValue(index,((ISafeDataRecord)record).GetInt16Safe(field));
  227. }
  228. else {
  229. this[index] = record.GetValue(field);
  230. }
  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. bool isDbNull = record.IsDBNull(field);
  310. if (isDbNull) {
  311. SetNull(index,false,isDbNull);
  312. return;
  313. }
  314. // if exception thrown, it should be caught in the caller method
  315. if (record is ISafeDataRecord) {
  316. SetValue(index,((ISafeDataRecord)record).GetInt32Safe(field));
  317. }
  318. else {
  319. this[index] = record.GetValue(field);
  320. }
  321. }
  322. internal override void CopyValue(int fromIndex, int toIndex)
  323. {
  324. base.CopyValue(fromIndex, toIndex);
  325. _values[toIndex] = _values[fromIndex];
  326. }
  327. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  328. {
  329. base.CopyValue(fromContainer, fromIndex, toIndex);
  330. _values[toIndex] = ((Int32DataContainer)fromContainer)._values[fromIndex];
  331. }
  332. internal override int CompareValues(int index1, int index2)
  333. {
  334. int i1 = _values[index1];
  335. int i2 = _values[index2];
  336. if (i1 == 0 || i2 == 0) {
  337. int cn = CompareNulls(index1, index2);
  338. if (cn != 0)
  339. return cn;
  340. }
  341. if ( i1 <= i2 ) {
  342. return ( i1 == i2 ) ? 0 : -1;
  343. }
  344. return 1;
  345. }
  346. internal override long GetInt64(int index)
  347. {
  348. return (long) _values[index];
  349. }
  350. #endregion //Methods
  351. }
  352. sealed class Int64DataContainer : AbstractDataContainer
  353. {
  354. #region Fields
  355. long[] _values;
  356. #endregion //Fields
  357. #region Properties
  358. internal override object this[int index] {
  359. get {
  360. if (IsNull(index)) {
  361. return DBNull.Value;
  362. }
  363. else {
  364. return _values[index];
  365. }
  366. }
  367. set {
  368. bool isDbNull = (value == DBNull.Value);
  369. if (value == null || isDbNull) {
  370. SetValue(index,0);
  371. }
  372. else if( value is long ) {
  373. SetValue(index,(long)value);
  374. }
  375. else {
  376. SetValue(index,Convert.ToInt64(value));
  377. }
  378. SetNull(index,value == null,isDbNull);
  379. }
  380. }
  381. internal override int Capacity {
  382. set {
  383. base.Capacity = value;
  384. if (_values == null) {
  385. _values = new long[value];
  386. }
  387. else {
  388. long[] tmp = new long[value];
  389. Array.Copy(_values,0,tmp,0,_values.Length);
  390. _values = tmp;
  391. }
  392. }
  393. }
  394. #endregion //Properties
  395. #region Methods
  396. private void SetValue(int index, long value)
  397. {
  398. _values[index] = value;
  399. }
  400. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  401. {
  402. bool isDbNull = record.IsDBNull(field);
  403. if (isDbNull) {
  404. SetNull(index,false,isDbNull);
  405. return;
  406. }
  407. // if exception thrown, it should be caught in the caller method
  408. if (record is ISafeDataRecord) {
  409. SetValue(index,((ISafeDataRecord)record).GetInt64Safe(field));
  410. }
  411. else {
  412. this[index] = record.GetValue(field);
  413. }
  414. }
  415. internal override void CopyValue(int fromIndex, int toIndex)
  416. {
  417. base.CopyValue(fromIndex, toIndex);
  418. _values[toIndex] = _values[fromIndex];
  419. }
  420. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  421. {
  422. base.CopyValue(fromContainer, fromIndex, toIndex);
  423. _values[toIndex] = ((Int64DataContainer)fromContainer)._values[fromIndex];
  424. }
  425. internal override int CompareValues(int index1, int index2)
  426. {
  427. long l1 = _values[index1];
  428. long l2 = _values[index2];
  429. if ( l1 == 0 || l2 == 0 ) {
  430. int cn = CompareNulls(index1, index2);
  431. if (cn != 0) {
  432. return cn;
  433. }
  434. }
  435. if ( l1 <= l2 ) {
  436. return ( l1 != l2 ) ? -1 : 0;
  437. }
  438. return 1;
  439. }
  440. internal override long GetInt64(int index)
  441. {
  442. return _values[index];
  443. }
  444. #endregion //Methods
  445. }
  446. sealed class SingleDataContainer : AbstractDataContainer
  447. {
  448. #region Fields
  449. float[] _values;
  450. #endregion //Fields
  451. #region Properties
  452. internal override object this[int index] {
  453. get {
  454. if (IsNull(index)) {
  455. return DBNull.Value;
  456. }
  457. else {
  458. return _values[index];
  459. }
  460. }
  461. set {
  462. bool isDbNull = (value == DBNull.Value);
  463. if (value == null || isDbNull) {
  464. SetValue(index,0);
  465. }
  466. else if( value is float ) {
  467. SetValue(index,(float)value);
  468. }
  469. else {
  470. SetValue(index,Convert.ToSingle(value));
  471. }
  472. SetNull(index,value == null,isDbNull);
  473. }
  474. }
  475. internal override int Capacity {
  476. set {
  477. base.Capacity = value;
  478. if (_values == null) {
  479. _values = new float[value];
  480. }
  481. else {
  482. float[] tmp = new float[value];
  483. Array.Copy(_values,0,tmp,0,_values.Length);
  484. _values = tmp;
  485. }
  486. }
  487. }
  488. #endregion //Properties
  489. #region Methods
  490. private void SetValue(int index, float value)
  491. {
  492. _values[index] = value;
  493. }
  494. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  495. {
  496. bool isDbNull = record.IsDBNull(field);
  497. if (isDbNull) {
  498. SetNull(index,false,isDbNull);
  499. return;
  500. }
  501. // if exception thrown, it should be caught in the caller method
  502. if (record is ISafeDataRecord) {
  503. SetValue(index,((ISafeDataRecord)record).GetFloatSafe(field));
  504. }
  505. else {
  506. this[index] = record.GetValue(field);
  507. }
  508. }
  509. internal override void CopyValue(int fromIndex, int toIndex)
  510. {
  511. base.CopyValue(fromIndex, toIndex);
  512. _values[toIndex] = _values[fromIndex];
  513. }
  514. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  515. {
  516. base.CopyValue(fromContainer, fromIndex, toIndex);
  517. _values[toIndex] = ((SingleDataContainer)fromContainer)._values[fromIndex];
  518. }
  519. internal override int CompareValues(int index1, int index2)
  520. {
  521. float f1 = _values[index1];
  522. float f2 = _values[index2];
  523. if ( f1 == 0 || f2 == 0 ) {
  524. int cn = CompareNulls(index1, index2);
  525. if (cn != 0) {
  526. return cn;
  527. }
  528. }
  529. if ( f1 <= f2 ) {
  530. return ( f1 != f2 ) ? -1 : 0;
  531. }
  532. return 1;
  533. }
  534. internal override long GetInt64(int index)
  535. {
  536. return Convert.ToInt64(_values[index]);
  537. }
  538. #endregion //Methods
  539. }
  540. sealed class DoubleDataContainer : AbstractDataContainer
  541. {
  542. #region Fields
  543. double[] _values;
  544. #endregion //Fields
  545. #region Properties
  546. internal override object this[int index] {
  547. get {
  548. if (IsNull(index)) {
  549. return DBNull.Value;
  550. }
  551. else {
  552. return _values[index];
  553. }
  554. }
  555. set {
  556. bool isDbNull = (value == DBNull.Value);
  557. if (value == null || isDbNull) {
  558. SetValue(index,0);
  559. }
  560. else if( value is double ) {
  561. SetValue(index,(double)value);
  562. }
  563. else {
  564. SetValue(index,Convert.ToDouble(value));
  565. }
  566. SetNull(index,value == null,isDbNull);
  567. }
  568. }
  569. internal override int Capacity {
  570. set {
  571. base.Capacity = value;
  572. if (_values == null) {
  573. _values = new double[value];
  574. }
  575. else {
  576. double[] tmp = new double[value];
  577. Array.Copy(_values,0,tmp,0,_values.Length);
  578. _values = tmp;
  579. }
  580. }
  581. }
  582. #endregion //Properties
  583. #region Methods
  584. private void SetValue(int index, double value)
  585. {
  586. _values[index] = value;
  587. }
  588. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  589. {
  590. bool isDbNull = record.IsDBNull(field);
  591. if (isDbNull) {
  592. SetNull(index,false,isDbNull);
  593. return;
  594. }
  595. // if exception thrown, it should be caught in the caller method
  596. if (record is ISafeDataRecord) {
  597. SetValue(index,((ISafeDataRecord)record).GetDoubleSafe(field));
  598. }
  599. else {
  600. this[index] = record.GetValue(field);
  601. }
  602. }
  603. internal override void CopyValue(int fromIndex, int toIndex)
  604. {
  605. base.CopyValue(fromIndex, toIndex);
  606. _values[toIndex] = _values[fromIndex];
  607. }
  608. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  609. {
  610. base.CopyValue(fromContainer, fromIndex, toIndex);
  611. _values[toIndex] = ((DoubleDataContainer)fromContainer)._values[fromIndex];
  612. }
  613. internal override int CompareValues(int index1, int index2)
  614. {
  615. double d1 = _values[index1];
  616. double d2 = _values[index2];
  617. if ( d1 == 0 || d2 == 0 ) {
  618. int cn = CompareNulls(index1, index2);
  619. if (cn != 0) {
  620. return cn;
  621. }
  622. }
  623. if ( d1 <= d2 ) {
  624. return ( d1 != d2 ) ? -1 : 0;
  625. }
  626. return 1;
  627. }
  628. internal override long GetInt64(int index)
  629. {
  630. return Convert.ToInt64(_values[index]);
  631. }
  632. #endregion //Methods
  633. }
  634. sealed class ByteDataContainer : AbstractDataContainer
  635. {
  636. #region Fields
  637. byte[] _values;
  638. #endregion //Fields
  639. #region Properties
  640. internal override object this[int index] {
  641. get {
  642. if (IsNull(index)) {
  643. return DBNull.Value;
  644. }
  645. else {
  646. return _values[index];
  647. }
  648. }
  649. set {
  650. bool isDbNull = (value == DBNull.Value);
  651. if (value == null || isDbNull) {
  652. SetValue(index,0);
  653. }
  654. else if( value is byte ) {
  655. SetValue(index,(byte)value);
  656. }
  657. else {
  658. SetValue(index,Convert.ToByte(value));
  659. }
  660. SetNull(index,value == null,isDbNull);
  661. }
  662. }
  663. internal override int Capacity {
  664. set {
  665. base.Capacity = value;
  666. if (_values == null) {
  667. _values = new byte[value];
  668. }
  669. else {
  670. byte[] tmp = new byte[value];
  671. Array.Copy(_values,0,tmp,0,_values.Length);
  672. _values = tmp;
  673. }
  674. }
  675. }
  676. #endregion //Properties
  677. #region Methods
  678. private void SetValue(int index, byte value)
  679. {
  680. _values[index] = value;
  681. }
  682. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  683. {
  684. bool isDbNull = record.IsDBNull(field);
  685. if (isDbNull) {
  686. SetNull(index,false,isDbNull);
  687. return;
  688. }
  689. // if exception thrown, it should be caught in the caller method
  690. if (record is ISafeDataRecord) {
  691. SetValue(index,((ISafeDataRecord)record).GetByteSafe(field));
  692. }
  693. else {
  694. this[index] = record.GetValue(field);
  695. }
  696. }
  697. internal override void CopyValue(int fromIndex, int toIndex)
  698. {
  699. base.CopyValue(fromIndex, toIndex);
  700. _values[toIndex] = _values[fromIndex];
  701. }
  702. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  703. {
  704. base.CopyValue(fromContainer, fromIndex, toIndex);
  705. _values[toIndex] = ((ByteDataContainer)fromContainer)._values[fromIndex];
  706. }
  707. internal override int CompareValues(int index1, int index2)
  708. {
  709. byte b1 = _values[index1];
  710. byte b2 = _values[index2];
  711. if ( b1 == 0 || b2 == 0 ) {
  712. int cn = CompareNulls(index1, index2);
  713. if (cn != 0) {
  714. return cn;
  715. }
  716. }
  717. return b1 - b2;
  718. }
  719. internal override long GetInt64(int index)
  720. {
  721. return (long) _values[index];
  722. }
  723. #endregion //Methods
  724. }
  725. sealed class BitDataContainer : AbstractDataContainer
  726. {
  727. #region Fields
  728. bool[] _values;
  729. #endregion //Fields
  730. #region Properties
  731. internal override object this[int index] {
  732. get {
  733. bool isNull = IsNull(index);
  734. if (isNull) {
  735. return DBNull.Value;
  736. }
  737. else {
  738. return _values[index];
  739. }
  740. }
  741. set {
  742. bool isDbNull = (value == DBNull.Value);
  743. if (value == null || isDbNull) {
  744. SetValue(index,false);
  745. }
  746. else if( value is bool ) {
  747. SetValue(index,(bool)value);
  748. }
  749. else {
  750. SetValue(index,Convert.ToBoolean(value));
  751. }
  752. SetNull(index,value == null,isDbNull);
  753. }
  754. }
  755. internal override int Capacity {
  756. set {
  757. base.Capacity = value;
  758. if (_values == null) {
  759. _values = new bool[value];
  760. }
  761. else {
  762. bool[] tmp = new bool[value];
  763. Array.Copy(_values,0,tmp,0,_values.Length);
  764. _values = tmp;
  765. }
  766. }
  767. }
  768. #endregion //Properties
  769. #region Methods
  770. private void SetValue(int index, bool value)
  771. {
  772. _values[index] = value;
  773. }
  774. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  775. {
  776. bool isDbNull = record.IsDBNull(field);
  777. if (isDbNull) {
  778. SetNull(index,false,isDbNull);
  779. return;
  780. }
  781. // if exception thrown, it should be caught in the caller method
  782. if (record is ISafeDataRecord) {
  783. SetValue(index,((ISafeDataRecord)record).GetBooleanSafe(field));
  784. }
  785. else {
  786. this[index] = record.GetValue(field);
  787. }
  788. }
  789. internal override void CopyValue(int fromIndex, int toIndex)
  790. {
  791. base.CopyValue(fromIndex, toIndex);
  792. _values[toIndex] = _values[fromIndex];
  793. }
  794. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  795. {
  796. base.CopyValue(fromContainer, fromIndex, toIndex);
  797. _values[toIndex] = ((BitDataContainer)fromContainer)._values[fromIndex];
  798. }
  799. internal override int CompareValues(int index1, int index2)
  800. {
  801. bool b1 = _values[index1];
  802. bool b2 = _values[index2];
  803. if ( b1 ^ b2 ) {
  804. return b1 ? 1 : -1;
  805. }
  806. if ( b1 ) {
  807. return 0;
  808. }
  809. return CompareNulls(index1, index2);
  810. }
  811. internal override long GetInt64(int index)
  812. {
  813. return Convert.ToInt64(_values[index]);
  814. }
  815. #endregion //Methods
  816. }
  817. abstract class AbstractObjectDataContainer : AbstractDataContainer
  818. {
  819. #region Fields
  820. object[] _values;
  821. #endregion //Fields
  822. #region Properties
  823. internal override object this[int index] {
  824. get {
  825. if (IsNull(index))
  826. return DBNull.Value;
  827. return _values[index];
  828. }
  829. set {
  830. SetValue(index,value);
  831. SetNull(index,value == null,value == DBNull.Value);
  832. }
  833. }
  834. internal override int Capacity {
  835. set {
  836. base.Capacity = value;
  837. if (_values == null) {
  838. _values = new object[value];
  839. }
  840. else {
  841. object[] tmp = new object[value];
  842. Array.Copy(_values,0,tmp,0,_values.Length);
  843. _values = tmp;
  844. }
  845. }
  846. }
  847. #endregion //Properties
  848. #region Methods
  849. protected virtual void SetValue(int index, object value)
  850. {
  851. if(value == null) {
  852. value = Column.DefaultValue;
  853. }
  854. _values[index] = value;
  855. }
  856. internal override void CopyValue(int fromIndex, int toIndex)
  857. {
  858. base.CopyValue(fromIndex, toIndex);
  859. _values[toIndex] = _values[fromIndex];
  860. }
  861. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  862. {
  863. base.CopyValue(fromContainer, fromIndex, toIndex);
  864. _values[toIndex] = ((AbstractObjectDataContainer)fromContainer)._values[fromIndex];
  865. }
  866. internal override int CompareValues(int index1, int index2)
  867. {
  868. object obj1 = _values[index1];
  869. object obj2 = _values[index2];
  870. if(obj1 == obj2)
  871. {
  872. return 0;
  873. }
  874. else
  875. {
  876. int cn = CompareNulls(index1, index2);
  877. if (cn != 0)
  878. return cn;
  879. if (obj1 is IComparable)
  880. {
  881. try
  882. {
  883. return ((IComparable)obj1).CompareTo(obj2);
  884. }
  885. catch
  886. {
  887. //just suppress
  888. }
  889. if (obj2 is IComparable)
  890. {
  891. obj2 = Convert.ChangeType(obj2, Type.GetTypeCode(obj1.GetType()));
  892. return ((IComparable)obj1).CompareTo(obj2);
  893. }
  894. }
  895. }
  896. return String.Compare(obj1.ToString(), obj2.ToString());
  897. }
  898. internal override long GetInt64(int index)
  899. {
  900. return Convert.ToInt64(_values[index]);
  901. }
  902. #endregion //Methods
  903. }
  904. sealed class ObjectDataContainer : AbstractObjectDataContainer
  905. {
  906. #region Methods
  907. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  908. {
  909. bool isDbNull = record.IsDBNull(field);
  910. if (isDbNull) {
  911. SetNull(index,false,isDbNull);
  912. return;
  913. }
  914. // if exception thrown, it should be caught
  915. // in the caller method
  916. SetValue(index,record.GetValue(field));
  917. }
  918. protected override void SetValue(int index, object value)
  919. {
  920. if(value != null && value != DBNull.Value && !Type.IsAssignableFrom(value.GetType()))
  921. value = Convert.ChangeType(value, Type);
  922. base.SetValue(index, value);
  923. }
  924. #endregion //Methods
  925. }
  926. sealed class DateTimeDataContainer : AbstractObjectDataContainer
  927. {
  928. #region Methods
  929. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  930. {
  931. bool isDbNull = record.IsDBNull(field);
  932. if (isDbNull) {
  933. SetNull(index,false,isDbNull);
  934. return;
  935. }
  936. // if exception thrown, it should be caught
  937. // in the caller method
  938. // if exception thrown, it should be caught in the caller method
  939. if (record is ISafeDataRecord) {
  940. SetValue(index,((ISafeDataRecord)record).GetDateTimeSafe(field));
  941. }
  942. else {
  943. this[index] = record.GetValue(field);
  944. }
  945. }
  946. protected override void SetValue(int index, object value)
  947. {
  948. if (value != null && value != DBNull.Value)
  949. value = Convert.ToDateTime(value);
  950. base.SetValue(index, value);
  951. }
  952. #endregion //Methods
  953. }
  954. sealed class DecimalDataContainer : AbstractObjectDataContainer
  955. {
  956. #region Methods
  957. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  958. {
  959. bool isDbNull = record.IsDBNull(field);
  960. if (isDbNull) {
  961. SetNull(index,false,isDbNull);
  962. return;
  963. }
  964. // if exception thrown, it should be caught in the caller method
  965. if (record is ISafeDataRecord) {
  966. SetValue(index,((ISafeDataRecord)record).GetDecimalSafe(field));
  967. }
  968. else {
  969. this[index] = record.GetValue(field);
  970. }
  971. }
  972. protected override void SetValue(int index, object value)
  973. {
  974. if (value != null && value != DBNull.Value)
  975. value = Convert.ToDecimal(value);
  976. base.SetValue(index, value);
  977. }
  978. #endregion //Methods
  979. }
  980. sealed class StringDataContainer : AbstractObjectDataContainer
  981. {
  982. #region Methods
  983. private void SetValue(int index, string value)
  984. {
  985. if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {
  986. throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");
  987. }
  988. base.SetValue(index,value);
  989. }
  990. protected override void SetValue(int index, object value)
  991. {
  992. if ( value != null && value != DBNull.Value ) {
  993. if ( value is string ) {
  994. SetValue(index, (string) value);
  995. }
  996. else {
  997. SetValue(index, Convert.ToString(value));
  998. }
  999. return;
  1000. }
  1001. base.SetValue(index, value);
  1002. }
  1003. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1004. {
  1005. bool isDbNull = record.IsDBNull(field);
  1006. if (isDbNull) {
  1007. SetNull(index,false,isDbNull);
  1008. return;
  1009. }
  1010. // if exception thrown, it should be caught
  1011. // in the caller method
  1012. if (record is ISafeDataRecord) {
  1013. SetValue(index,((ISafeDataRecord)record).GetStringSafe(field));
  1014. }
  1015. else {
  1016. this[index] = record.GetValue(field);
  1017. }
  1018. }
  1019. internal override int CompareValues(int index1, int index2)
  1020. {
  1021. bool isNull1 = IsNull(index1);
  1022. bool isNull2 = IsNull(index2);
  1023. if (isNull1) {
  1024. return isNull2 ? 0 : -1;
  1025. }
  1026. else {
  1027. if (isNull2) {
  1028. return 1;
  1029. }
  1030. }
  1031. return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive);
  1032. }
  1033. #endregion //Methods
  1034. }
  1035. sealed class CharDataContainer : AbstractDataContainer
  1036. {
  1037. #region Fields
  1038. char[] _values;
  1039. #endregion //Fields
  1040. #region Properties
  1041. internal override object this[int index] {
  1042. get {
  1043. if (IsNull(index)) {
  1044. return DBNull.Value;
  1045. }
  1046. else {
  1047. return _values[index];
  1048. }
  1049. }
  1050. set {
  1051. bool isDbNull = (value == DBNull.Value);
  1052. if (value == null || isDbNull) {
  1053. SetValue(index,'\0');
  1054. }
  1055. else if( value is char ) {
  1056. SetValue(index,(char)value);
  1057. }
  1058. else {
  1059. SetValue(index,Convert.ToChar(value));
  1060. }
  1061. SetNull(index,value == null,isDbNull);
  1062. }
  1063. }
  1064. internal override int Capacity {
  1065. set {
  1066. base.Capacity = value;
  1067. if (_values == null) {
  1068. _values = new char[value];
  1069. }
  1070. else {
  1071. char[] tmp = new char[value];
  1072. Array.Copy(_values,0,tmp,0,_values.Length);
  1073. _values = tmp;
  1074. }
  1075. }
  1076. }
  1077. #endregion //Properties
  1078. #region Methods
  1079. private void SetValue(int index, char value)
  1080. {
  1081. _values[index] = value;
  1082. }
  1083. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1084. {
  1085. bool isDbNull = record.IsDBNull(field);
  1086. if (isDbNull) {
  1087. SetNull(index,false,isDbNull);
  1088. return;
  1089. }
  1090. // if exception thrown, it should be caught in the caller method
  1091. if (record is ISafeDataRecord) {
  1092. SetValue(index,((ISafeDataRecord)record).GetCharSafe(field));
  1093. }
  1094. else {
  1095. this[index] = record.GetValue(field);
  1096. }
  1097. }
  1098. internal override void CopyValue(int fromIndex, int toIndex)
  1099. {
  1100. base.CopyValue(fromIndex, toIndex);
  1101. _values[toIndex] = _values[fromIndex];
  1102. }
  1103. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1104. {
  1105. base.CopyValue(fromContainer, fromIndex, toIndex);
  1106. _values[toIndex] = ((CharDataContainer)fromContainer)._values[fromIndex];
  1107. }
  1108. internal override int CompareValues(int index1, int index2)
  1109. {
  1110. char c1 = _values[index1];
  1111. char c2 = _values[index2];
  1112. if ( c1 == '\0' || c2 == '\0' )
  1113. {
  1114. int cn = CompareNulls(index1, index2);
  1115. if (cn != 0)
  1116. return cn;
  1117. }
  1118. return c1 - c2;
  1119. }
  1120. internal override long GetInt64(int index)
  1121. {
  1122. return Convert.ToInt64(_values[index]);
  1123. }
  1124. #endregion //Methods
  1125. }
  1126. sealed class UInt16DataContainer : AbstractDataContainer
  1127. {
  1128. #region Fields
  1129. ushort[] _values;
  1130. #endregion //Fields
  1131. #region Properties
  1132. internal override object this[int index] {
  1133. get {
  1134. if (IsNull(index)) {
  1135. return DBNull.Value;
  1136. }
  1137. else {
  1138. return _values[index];
  1139. }
  1140. }
  1141. set {
  1142. bool isDbNull = (value == DBNull.Value);
  1143. if (value == null || isDbNull) {
  1144. SetValue(index,0);
  1145. }
  1146. else if( value is ushort ) {
  1147. SetValue(index,(ushort)value);
  1148. }
  1149. else {
  1150. SetValue(index,Convert.ToUInt16(value));
  1151. }
  1152. SetNull(index,value == null,isDbNull);
  1153. }
  1154. }
  1155. internal override int Capacity {
  1156. set {
  1157. base.Capacity = value;
  1158. if (_values == null) {
  1159. _values = new ushort[value];
  1160. }
  1161. else {
  1162. ushort[] tmp = new ushort[value];
  1163. Array.Copy(_values,0,tmp,0,_values.Length);
  1164. _values = tmp;
  1165. }
  1166. }
  1167. }
  1168. #endregion //Properties
  1169. #region Methods
  1170. private void SetValue(int index, ushort value)
  1171. {
  1172. _values[index] = value;
  1173. }
  1174. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1175. {
  1176. bool isDbNull = record.IsDBNull(field);
  1177. if (isDbNull) {
  1178. SetNull(index,false,isDbNull);
  1179. return;
  1180. }
  1181. // if exception thrown, it should be caught in the caller method
  1182. if (record is ISafeDataRecord) {
  1183. SetValue(index,(ushort)((ISafeDataRecord)record).GetInt16Safe(field));
  1184. }
  1185. else {
  1186. this[index] = record.GetValue(field);
  1187. }
  1188. }
  1189. internal override void CopyValue(int fromIndex, int toIndex)
  1190. {
  1191. base.CopyValue(fromIndex, toIndex);
  1192. _values[toIndex] = _values[fromIndex];
  1193. }
  1194. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1195. {
  1196. base.CopyValue(fromContainer, fromIndex, toIndex);
  1197. _values[toIndex] = ((UInt16DataContainer)fromContainer)._values[fromIndex];
  1198. }
  1199. internal override int CompareValues(int index1, int index2)
  1200. {
  1201. ushort s1 = _values[index1];
  1202. ushort s2 = _values[index2];
  1203. if ( s1 == 0 || s2 == 0 ) {
  1204. int cn = CompareNulls(index1, index2);
  1205. if (cn != 0)
  1206. return cn;
  1207. }
  1208. return s1 - s2;
  1209. }
  1210. internal override long GetInt64(int index)
  1211. {
  1212. return Convert.ToInt64(_values[index]);
  1213. }
  1214. #endregion //Methods
  1215. }
  1216. sealed class UInt32DataContainer : AbstractDataContainer
  1217. {
  1218. #region Fields
  1219. uint[] _values;
  1220. #endregion //Fields
  1221. #region Properties
  1222. internal override object this[int index] {
  1223. get {
  1224. if (IsNull(index)) {
  1225. return DBNull.Value;
  1226. }
  1227. else {
  1228. return _values[index];
  1229. }
  1230. }
  1231. set {
  1232. bool isDbNull = (value == DBNull.Value);
  1233. if (value == null || isDbNull) {
  1234. SetValue(index,0);
  1235. }
  1236. else if( value is uint ) {
  1237. SetValue(index,(uint)value);
  1238. }
  1239. else {
  1240. SetValue(index,Convert.ToUInt32(value));
  1241. }
  1242. SetNull(index,value == null,isDbNull);
  1243. }
  1244. }
  1245. internal override int Capacity {
  1246. set {
  1247. base.Capacity = value;
  1248. if (_values == null) {
  1249. _values = new uint[value];
  1250. }
  1251. else {
  1252. uint[] tmp = new uint[value];
  1253. Array.Copy(_values,0,tmp,0,_values.Length);
  1254. _values = tmp;
  1255. }
  1256. }
  1257. }
  1258. #endregion //Properties
  1259. #region Methods
  1260. private void SetValue(int index, uint value)
  1261. {
  1262. _values[index] = value;
  1263. }
  1264. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1265. {
  1266. bool isDbNull = record.IsDBNull(field);
  1267. if (isDbNull) {
  1268. SetNull(index,false,isDbNull);
  1269. return;
  1270. }
  1271. // if exception thrown, it should be caught in the caller method
  1272. if (record is ISafeDataRecord) {
  1273. SetValue(index,(uint)((ISafeDataRecord)record).GetInt32Safe(field));
  1274. }
  1275. else {
  1276. this[index] = record.GetValue(field);
  1277. }
  1278. }
  1279. internal override void CopyValue(int fromIndex, int toIndex)
  1280. {
  1281. base.CopyValue(fromIndex, toIndex);
  1282. _values[toIndex] = _values[fromIndex];
  1283. }
  1284. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1285. {
  1286. base.CopyValue(fromContainer, fromIndex, toIndex);
  1287. _values[toIndex] = ((UInt32DataContainer)fromContainer)._values[fromIndex];
  1288. }
  1289. internal override int CompareValues(int index1, int index2)
  1290. {
  1291. uint i1 = _values[index1];
  1292. uint i2 = _values[index2];
  1293. if ( i1 == 0 || i2 == 0 ) {
  1294. int cn = CompareNulls(index1, index2);
  1295. if (cn != 0)
  1296. return cn;
  1297. }
  1298. if ( i1 <= i2 ) {
  1299. return ( i1 != i2 ) ? -1 : 0;
  1300. }
  1301. return 1;
  1302. }
  1303. internal override long GetInt64(int index)
  1304. {
  1305. return Convert.ToInt64(_values[index]);
  1306. }
  1307. #endregion //Methods
  1308. }
  1309. sealed class UInt64DataContainer : AbstractDataContainer
  1310. {
  1311. #region Fields
  1312. ulong[] _values;
  1313. #endregion //Fields
  1314. #region Properties
  1315. internal override object this[int index] {
  1316. get {
  1317. if (IsNull(index)) {
  1318. return DBNull.Value;
  1319. }
  1320. else {
  1321. return _values[index];
  1322. }
  1323. }
  1324. set {
  1325. bool isDbNull = (value == DBNull.Value);
  1326. if (value == null || isDbNull) {
  1327. SetValue(index,0);
  1328. }
  1329. else if( value is ulong ) {
  1330. SetValue(index,(ulong)value);
  1331. }
  1332. else {
  1333. SetValue(index,Convert.ToUInt64(value));
  1334. }
  1335. SetNull(index,value == null,isDbNull);
  1336. }
  1337. }
  1338. internal override int Capacity {
  1339. set {
  1340. base.Capacity = value;
  1341. if (_values == null) {
  1342. _values = new ulong[value];
  1343. }
  1344. else {
  1345. ulong[] tmp = new ulong[value];
  1346. Array.Copy(_values,0,tmp,0,_values.Length);
  1347. _values = tmp;
  1348. }
  1349. }
  1350. }
  1351. #endregion //Properties
  1352. #region Methods
  1353. private void SetValue(int index, ulong value)
  1354. {
  1355. _values[index] = value;
  1356. }
  1357. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1358. {
  1359. bool isDbNull = record.IsDBNull(field);
  1360. if (isDbNull) {
  1361. SetNull(index,false,isDbNull);
  1362. return;
  1363. }
  1364. // if exception thrown, it should be caught in the caller method
  1365. if (record is ISafeDataRecord) {
  1366. SetValue(index,(ulong)((ISafeDataRecord)record).GetInt64Safe(field));
  1367. }
  1368. else {
  1369. this[index] = record.GetValue(field);
  1370. }
  1371. }
  1372. internal override void CopyValue(int fromIndex, int toIndex)
  1373. {
  1374. base.CopyValue(fromIndex, toIndex);
  1375. _values[toIndex] = _values[fromIndex];
  1376. }
  1377. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1378. {
  1379. base.CopyValue(fromContainer, fromIndex, toIndex);
  1380. _values[toIndex] = ((UInt64DataContainer)fromContainer)._values[fromIndex];
  1381. }
  1382. internal override int CompareValues(int index1, int index2)
  1383. {
  1384. ulong l1 = _values[index1];
  1385. ulong l2 = _values[index2];
  1386. if ( l1 == 0 || l2 == 0 ) {
  1387. int cn = CompareNulls(index1, index2);
  1388. if (cn != 0) {
  1389. return cn;
  1390. }
  1391. }
  1392. if ( l1 <= l2 ) {
  1393. return ( l1 != l2 ) ? -1 : 0;
  1394. }
  1395. return 1;
  1396. }
  1397. internal override long GetInt64(int index)
  1398. {
  1399. return Convert.ToInt64(_values[index]);
  1400. }
  1401. #endregion //Methods
  1402. }
  1403. sealed class SByteDataContainer : AbstractDataContainer
  1404. {
  1405. #region Fields
  1406. sbyte[] _values;
  1407. #endregion //Fields
  1408. #region Properties
  1409. internal override object this[int index] {
  1410. get {
  1411. if (IsNull(index)) {
  1412. return DBNull.Value;
  1413. }
  1414. else {
  1415. return _values[index];
  1416. }
  1417. }
  1418. set {
  1419. bool isDbNull = (value == DBNull.Value);
  1420. if (value == null || isDbNull) {
  1421. SetValue(index,0);
  1422. }
  1423. else if( value is sbyte ) {
  1424. SetValue(index,(sbyte)value);
  1425. }
  1426. else {
  1427. SetValue(index,Convert.ToSByte(value));
  1428. }
  1429. SetNull(index,value == null,isDbNull);
  1430. }
  1431. }
  1432. internal override int Capacity {
  1433. set {
  1434. base.Capacity = value;
  1435. if (_values == null) {
  1436. _values = new sbyte[value];
  1437. }
  1438. else {
  1439. sbyte[] tmp = new sbyte[value];
  1440. Array.Copy(_values,0,tmp,0,_values.Length);
  1441. _values = tmp;
  1442. }
  1443. }
  1444. }
  1445. #endregion //Properties
  1446. #region Methods
  1447. private void SetValue(int index, sbyte value)
  1448. {
  1449. _values[index] = value;
  1450. }
  1451. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1452. {
  1453. bool isDbNull = record.IsDBNull(field);
  1454. if (isDbNull) {
  1455. SetNull(index,false,isDbNull);
  1456. return;
  1457. }
  1458. // if exception thrown, it should be caught in the caller method
  1459. if (record is ISafeDataRecord) {
  1460. SetValue(index,(sbyte)((ISafeDataRecord)record).GetByteSafe(field));
  1461. }
  1462. else {
  1463. this[index] = record.GetValue(field);
  1464. }
  1465. }
  1466. internal override void CopyValue(int fromIndex, int toIndex)
  1467. {
  1468. base.CopyValue(fromIndex, toIndex);
  1469. _values[toIndex] = _values[fromIndex];
  1470. }
  1471. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1472. {
  1473. base.CopyValue(fromContainer, fromIndex, toIndex);
  1474. _values[toIndex] = ((SByteDataContainer)fromContainer)._values[fromIndex];
  1475. }
  1476. internal override int CompareValues(int index1, int index2)
  1477. {
  1478. sbyte b1 = _values[index1];
  1479. sbyte b2 = _values[index2];
  1480. if ( b1 == 0 || b2 == 0 ) {
  1481. int cn = CompareNulls(index1, index2);
  1482. if (cn != 0) {
  1483. return cn;
  1484. }
  1485. }
  1486. return b1 - b2;
  1487. }
  1488. internal override long GetInt64(int index)
  1489. {
  1490. return Convert.ToSByte(_values[index]);
  1491. }
  1492. #endregion //Methods
  1493. }
  1494. }
  1495. }