DataContainer.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  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. #endregion //Methods
  919. }
  920. sealed class DateTimeDataContainer : AbstractObjectDataContainer
  921. {
  922. #region Methods
  923. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  924. {
  925. bool isDbNull = record.IsDBNull(field);
  926. if (isDbNull) {
  927. SetNull(index,false,isDbNull);
  928. return;
  929. }
  930. // if exception thrown, it should be caught
  931. // in the caller method
  932. // if exception thrown, it should be caught in the caller method
  933. if (record is ISafeDataRecord) {
  934. SetValue(index,((ISafeDataRecord)record).GetDateTimeSafe(field));
  935. }
  936. else {
  937. this[index] = record.GetValue(field);
  938. }
  939. }
  940. protected override void SetValue(int index, object value)
  941. {
  942. if (value != null && value != DBNull.Value)
  943. value = Convert.ToDateTime(value);
  944. base.SetValue(index, value);
  945. }
  946. #endregion //Methods
  947. }
  948. sealed class DecimalDataContainer : AbstractObjectDataContainer
  949. {
  950. #region Methods
  951. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  952. {
  953. bool isDbNull = record.IsDBNull(field);
  954. if (isDbNull) {
  955. SetNull(index,false,isDbNull);
  956. return;
  957. }
  958. // if exception thrown, it should be caught in the caller method
  959. if (record is ISafeDataRecord) {
  960. SetValue(index,((ISafeDataRecord)record).GetDecimalSafe(field));
  961. }
  962. else {
  963. this[index] = record.GetValue(field);
  964. }
  965. }
  966. protected override void SetValue(int index, object value)
  967. {
  968. if (value != null && value != DBNull.Value)
  969. value = Convert.ToDecimal(value);
  970. base.SetValue(index, value);
  971. }
  972. #endregion //Methods
  973. }
  974. sealed class StringDataContainer : AbstractObjectDataContainer
  975. {
  976. #region Methods
  977. private void SetValue(int index, string value)
  978. {
  979. if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {
  980. throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");
  981. }
  982. base.SetValue(index,value);
  983. }
  984. protected override void SetValue(int index, object value)
  985. {
  986. if ( value != null && value != DBNull.Value ) {
  987. if ( value is string ) {
  988. SetValue(index, (string) value);
  989. }
  990. else {
  991. SetValue(index, Convert.ToString(value));
  992. }
  993. return;
  994. }
  995. base.SetValue(index, value);
  996. }
  997. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  998. {
  999. bool isDbNull = record.IsDBNull(field);
  1000. if (isDbNull) {
  1001. SetNull(index,false,isDbNull);
  1002. return;
  1003. }
  1004. // if exception thrown, it should be caught
  1005. // in the caller method
  1006. if (record is ISafeDataRecord) {
  1007. SetValue(index,((ISafeDataRecord)record).GetStringSafe(field));
  1008. }
  1009. else {
  1010. this[index] = record.GetValue(field);
  1011. }
  1012. }
  1013. internal override int CompareValues(int index1, int index2)
  1014. {
  1015. bool isNull1 = IsNull(index1);
  1016. bool isNull2 = IsNull(index2);
  1017. if (isNull1) {
  1018. return isNull2 ? 0 : -1;
  1019. }
  1020. else {
  1021. if (isNull2) {
  1022. return 1;
  1023. }
  1024. }
  1025. return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive);
  1026. }
  1027. #endregion //Methods
  1028. }
  1029. sealed class CharDataContainer : AbstractDataContainer
  1030. {
  1031. #region Fields
  1032. char[] _values;
  1033. #endregion //Fields
  1034. #region Properties
  1035. internal override object this[int index] {
  1036. get {
  1037. if (IsNull(index)) {
  1038. return DBNull.Value;
  1039. }
  1040. else {
  1041. return _values[index];
  1042. }
  1043. }
  1044. set {
  1045. bool isDbNull = (value == DBNull.Value);
  1046. if (value == null || isDbNull) {
  1047. SetValue(index,'\0');
  1048. }
  1049. else if( value is char ) {
  1050. SetValue(index,(char)value);
  1051. }
  1052. else {
  1053. SetValue(index,Convert.ToChar(value));
  1054. }
  1055. SetNull(index,value == null,isDbNull);
  1056. }
  1057. }
  1058. internal override int Capacity {
  1059. set {
  1060. base.Capacity = value;
  1061. if (_values == null) {
  1062. _values = new char[value];
  1063. }
  1064. else {
  1065. char[] tmp = new char[value];
  1066. Array.Copy(_values,0,tmp,0,_values.Length);
  1067. _values = tmp;
  1068. }
  1069. }
  1070. }
  1071. #endregion //Properties
  1072. #region Methods
  1073. private void SetValue(int index, char value)
  1074. {
  1075. _values[index] = value;
  1076. }
  1077. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1078. {
  1079. bool isDbNull = record.IsDBNull(field);
  1080. if (isDbNull) {
  1081. SetNull(index,false,isDbNull);
  1082. return;
  1083. }
  1084. // if exception thrown, it should be caught in the caller method
  1085. if (record is ISafeDataRecord) {
  1086. SetValue(index,((ISafeDataRecord)record).GetCharSafe(field));
  1087. }
  1088. else {
  1089. this[index] = record.GetValue(field);
  1090. }
  1091. }
  1092. internal override void CopyValue(int fromIndex, int toIndex)
  1093. {
  1094. base.CopyValue(fromIndex, toIndex);
  1095. _values[toIndex] = _values[fromIndex];
  1096. }
  1097. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1098. {
  1099. base.CopyValue(fromContainer, fromIndex, toIndex);
  1100. _values[toIndex] = ((CharDataContainer)fromContainer)._values[fromIndex];
  1101. }
  1102. internal override int CompareValues(int index1, int index2)
  1103. {
  1104. char c1 = _values[index1];
  1105. char c2 = _values[index2];
  1106. if ( c1 == '\0' || c2 == '\0' )
  1107. {
  1108. int cn = CompareNulls(index1, index2);
  1109. if (cn != 0)
  1110. return cn;
  1111. }
  1112. return c1 - c2;
  1113. }
  1114. internal override long GetInt64(int index)
  1115. {
  1116. return Convert.ToInt64(_values[index]);
  1117. }
  1118. #endregion //Methods
  1119. }
  1120. sealed class UInt16DataContainer : AbstractDataContainer
  1121. {
  1122. #region Fields
  1123. ushort[] _values;
  1124. #endregion //Fields
  1125. #region Properties
  1126. internal override object this[int index] {
  1127. get {
  1128. if (IsNull(index)) {
  1129. return DBNull.Value;
  1130. }
  1131. else {
  1132. return _values[index];
  1133. }
  1134. }
  1135. set {
  1136. bool isDbNull = (value == DBNull.Value);
  1137. if (value == null || isDbNull) {
  1138. SetValue(index,0);
  1139. }
  1140. else if( value is ushort ) {
  1141. SetValue(index,(ushort)value);
  1142. }
  1143. else {
  1144. SetValue(index,Convert.ToUInt16(value));
  1145. }
  1146. SetNull(index,value == null,isDbNull);
  1147. }
  1148. }
  1149. internal override int Capacity {
  1150. set {
  1151. base.Capacity = value;
  1152. if (_values == null) {
  1153. _values = new ushort[value];
  1154. }
  1155. else {
  1156. ushort[] tmp = new ushort[value];
  1157. Array.Copy(_values,0,tmp,0,_values.Length);
  1158. _values = tmp;
  1159. }
  1160. }
  1161. }
  1162. #endregion //Properties
  1163. #region Methods
  1164. private void SetValue(int index, ushort value)
  1165. {
  1166. _values[index] = value;
  1167. }
  1168. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1169. {
  1170. bool isDbNull = record.IsDBNull(field);
  1171. if (isDbNull) {
  1172. SetNull(index,false,isDbNull);
  1173. return;
  1174. }
  1175. // if exception thrown, it should be caught in the caller method
  1176. if (record is ISafeDataRecord) {
  1177. SetValue(index,(ushort)((ISafeDataRecord)record).GetInt16Safe(field));
  1178. }
  1179. else {
  1180. this[index] = record.GetValue(field);
  1181. }
  1182. }
  1183. internal override void CopyValue(int fromIndex, int toIndex)
  1184. {
  1185. base.CopyValue(fromIndex, toIndex);
  1186. _values[toIndex] = _values[fromIndex];
  1187. }
  1188. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1189. {
  1190. base.CopyValue(fromContainer, fromIndex, toIndex);
  1191. _values[toIndex] = ((UInt16DataContainer)fromContainer)._values[fromIndex];
  1192. }
  1193. internal override int CompareValues(int index1, int index2)
  1194. {
  1195. ushort s1 = _values[index1];
  1196. ushort s2 = _values[index2];
  1197. if ( s1 == 0 || s2 == 0 ) {
  1198. int cn = CompareNulls(index1, index2);
  1199. if (cn != 0)
  1200. return cn;
  1201. }
  1202. return s1 - s2;
  1203. }
  1204. internal override long GetInt64(int index)
  1205. {
  1206. return Convert.ToInt64(_values[index]);
  1207. }
  1208. #endregion //Methods
  1209. }
  1210. sealed class UInt32DataContainer : AbstractDataContainer
  1211. {
  1212. #region Fields
  1213. uint[] _values;
  1214. #endregion //Fields
  1215. #region Properties
  1216. internal override object this[int index] {
  1217. get {
  1218. if (IsNull(index)) {
  1219. return DBNull.Value;
  1220. }
  1221. else {
  1222. return _values[index];
  1223. }
  1224. }
  1225. set {
  1226. bool isDbNull = (value == DBNull.Value);
  1227. if (value == null || isDbNull) {
  1228. SetValue(index,0);
  1229. }
  1230. else if( value is uint ) {
  1231. SetValue(index,(uint)value);
  1232. }
  1233. else {
  1234. SetValue(index,Convert.ToUInt32(value));
  1235. }
  1236. SetNull(index,value == null,isDbNull);
  1237. }
  1238. }
  1239. internal override int Capacity {
  1240. set {
  1241. base.Capacity = value;
  1242. if (_values == null) {
  1243. _values = new uint[value];
  1244. }
  1245. else {
  1246. uint[] tmp = new uint[value];
  1247. Array.Copy(_values,0,tmp,0,_values.Length);
  1248. _values = tmp;
  1249. }
  1250. }
  1251. }
  1252. #endregion //Properties
  1253. #region Methods
  1254. private void SetValue(int index, uint value)
  1255. {
  1256. _values[index] = value;
  1257. }
  1258. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1259. {
  1260. bool isDbNull = record.IsDBNull(field);
  1261. if (isDbNull) {
  1262. SetNull(index,false,isDbNull);
  1263. return;
  1264. }
  1265. // if exception thrown, it should be caught in the caller method
  1266. if (record is ISafeDataRecord) {
  1267. SetValue(index,(uint)((ISafeDataRecord)record).GetInt32Safe(field));
  1268. }
  1269. else {
  1270. this[index] = record.GetValue(field);
  1271. }
  1272. }
  1273. internal override void CopyValue(int fromIndex, int toIndex)
  1274. {
  1275. base.CopyValue(fromIndex, toIndex);
  1276. _values[toIndex] = _values[fromIndex];
  1277. }
  1278. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1279. {
  1280. base.CopyValue(fromContainer, fromIndex, toIndex);
  1281. _values[toIndex] = ((UInt32DataContainer)fromContainer)._values[fromIndex];
  1282. }
  1283. internal override int CompareValues(int index1, int index2)
  1284. {
  1285. uint i1 = _values[index1];
  1286. uint i2 = _values[index2];
  1287. if ( i1 == 0 || i2 == 0 ) {
  1288. int cn = CompareNulls(index1, index2);
  1289. if (cn != 0)
  1290. return cn;
  1291. }
  1292. if ( i1 <= i2 ) {
  1293. return ( i1 != i2 ) ? -1 : 0;
  1294. }
  1295. return 1;
  1296. }
  1297. internal override long GetInt64(int index)
  1298. {
  1299. return Convert.ToInt64(_values[index]);
  1300. }
  1301. #endregion //Methods
  1302. }
  1303. sealed class UInt64DataContainer : AbstractDataContainer
  1304. {
  1305. #region Fields
  1306. ulong[] _values;
  1307. #endregion //Fields
  1308. #region Properties
  1309. internal override object this[int index] {
  1310. get {
  1311. if (IsNull(index)) {
  1312. return DBNull.Value;
  1313. }
  1314. else {
  1315. return _values[index];
  1316. }
  1317. }
  1318. set {
  1319. bool isDbNull = (value == DBNull.Value);
  1320. if (value == null || isDbNull) {
  1321. SetValue(index,0);
  1322. }
  1323. else if( value is ulong ) {
  1324. SetValue(index,(ulong)value);
  1325. }
  1326. else {
  1327. SetValue(index,Convert.ToUInt64(value));
  1328. }
  1329. SetNull(index,value == null,isDbNull);
  1330. }
  1331. }
  1332. internal override int Capacity {
  1333. set {
  1334. base.Capacity = value;
  1335. if (_values == null) {
  1336. _values = new ulong[value];
  1337. }
  1338. else {
  1339. ulong[] tmp = new ulong[value];
  1340. Array.Copy(_values,0,tmp,0,_values.Length);
  1341. _values = tmp;
  1342. }
  1343. }
  1344. }
  1345. #endregion //Properties
  1346. #region Methods
  1347. private void SetValue(int index, ulong value)
  1348. {
  1349. _values[index] = value;
  1350. }
  1351. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1352. {
  1353. bool isDbNull = record.IsDBNull(field);
  1354. if (isDbNull) {
  1355. SetNull(index,false,isDbNull);
  1356. return;
  1357. }
  1358. // if exception thrown, it should be caught in the caller method
  1359. if (record is ISafeDataRecord) {
  1360. SetValue(index,(ulong)((ISafeDataRecord)record).GetInt64Safe(field));
  1361. }
  1362. else {
  1363. this[index] = record.GetValue(field);
  1364. }
  1365. }
  1366. internal override void CopyValue(int fromIndex, int toIndex)
  1367. {
  1368. base.CopyValue(fromIndex, toIndex);
  1369. _values[toIndex] = _values[fromIndex];
  1370. }
  1371. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1372. {
  1373. base.CopyValue(fromContainer, fromIndex, toIndex);
  1374. _values[toIndex] = ((UInt64DataContainer)fromContainer)._values[fromIndex];
  1375. }
  1376. internal override int CompareValues(int index1, int index2)
  1377. {
  1378. ulong l1 = _values[index1];
  1379. ulong l2 = _values[index2];
  1380. if ( l1 == 0 || l2 == 0 ) {
  1381. int cn = CompareNulls(index1, index2);
  1382. if (cn != 0) {
  1383. return cn;
  1384. }
  1385. }
  1386. if ( l1 <= l2 ) {
  1387. return ( l1 != l2 ) ? -1 : 0;
  1388. }
  1389. return 1;
  1390. }
  1391. internal override long GetInt64(int index)
  1392. {
  1393. return Convert.ToInt64(_values[index]);
  1394. }
  1395. #endregion //Methods
  1396. }
  1397. sealed class SByteDataContainer : AbstractDataContainer
  1398. {
  1399. #region Fields
  1400. sbyte[] _values;
  1401. #endregion //Fields
  1402. #region Properties
  1403. internal override object this[int index] {
  1404. get {
  1405. if (IsNull(index)) {
  1406. return DBNull.Value;
  1407. }
  1408. else {
  1409. return _values[index];
  1410. }
  1411. }
  1412. set {
  1413. bool isDbNull = (value == DBNull.Value);
  1414. if (value == null || isDbNull) {
  1415. SetValue(index,0);
  1416. }
  1417. else if( value is sbyte ) {
  1418. SetValue(index,(sbyte)value);
  1419. }
  1420. else {
  1421. SetValue(index,Convert.ToSByte(value));
  1422. }
  1423. SetNull(index,value == null,isDbNull);
  1424. }
  1425. }
  1426. internal override int Capacity {
  1427. set {
  1428. base.Capacity = value;
  1429. if (_values == null) {
  1430. _values = new sbyte[value];
  1431. }
  1432. else {
  1433. sbyte[] tmp = new sbyte[value];
  1434. Array.Copy(_values,0,tmp,0,_values.Length);
  1435. _values = tmp;
  1436. }
  1437. }
  1438. }
  1439. #endregion //Properties
  1440. #region Methods
  1441. private void SetValue(int index, sbyte value)
  1442. {
  1443. _values[index] = value;
  1444. }
  1445. internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
  1446. {
  1447. bool isDbNull = record.IsDBNull(field);
  1448. if (isDbNull) {
  1449. SetNull(index,false,isDbNull);
  1450. return;
  1451. }
  1452. // if exception thrown, it should be caught in the caller method
  1453. if (record is ISafeDataRecord) {
  1454. SetValue(index,(sbyte)((ISafeDataRecord)record).GetByteSafe(field));
  1455. }
  1456. else {
  1457. this[index] = record.GetValue(field);
  1458. }
  1459. }
  1460. internal override void CopyValue(int fromIndex, int toIndex)
  1461. {
  1462. base.CopyValue(fromIndex, toIndex);
  1463. _values[toIndex] = _values[fromIndex];
  1464. }
  1465. internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
  1466. {
  1467. base.CopyValue(fromContainer, fromIndex, toIndex);
  1468. _values[toIndex] = ((SByteDataContainer)fromContainer)._values[fromIndex];
  1469. }
  1470. internal override int CompareValues(int index1, int index2)
  1471. {
  1472. sbyte b1 = _values[index1];
  1473. sbyte b2 = _values[index2];
  1474. if ( b1 == 0 || b2 == 0 ) {
  1475. int cn = CompareNulls(index1, index2);
  1476. if (cn != 0) {
  1477. return cn;
  1478. }
  1479. }
  1480. return b1 - b2;
  1481. }
  1482. internal override long GetInt64(int index)
  1483. {
  1484. return Convert.ToSByte(_values[index]);
  1485. }
  1486. #endregion //Methods
  1487. }
  1488. }
  1489. }