1 //------------------------------------------------------------------------------
2 // <copyright file="SQLCharsStorage.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 // <owner current="false" primary="false">Microsoft</owner>
8 //------------------------------------------------------------------------------
10 namespace System.Data.Common {
14 using System.Xml.Serialization;
15 using System.Data.SqlTypes;
16 using System.Diagnostics;
17 using System.Globalization;
18 using System.Collections;
20 internal sealed class SqlCharsStorage : DataStorage {
22 private SqlChars[] values;
24 public SqlCharsStorage(DataColumn column)
25 : base(column, typeof(SqlChars), SqlChars.Null, SqlChars.Null, StorageType.SqlChars) {
28 override public Object Aggregate(int[] records, AggregateType kind) {
31 case AggregateType.First:
32 if (records.Length > 0) {
33 return values[records[0]];
35 return null;// no data => null
37 case AggregateType.Count:
39 for (int i = 0; i < records.Length; i++) {
40 if (!IsNull(records[i]))
46 catch (OverflowException) {
47 throw ExprException.Overflow(typeof(SqlChars));
49 throw ExceptionBuilder.AggregateException(kind, DataType);
52 override public int Compare(int recordNo1, int recordNo2) {
53 // throw ExceptionBuilder.IComparableNotDefined;
57 override public int CompareValueTo(int recordNo, Object value) {
58 // throw ExceptionBuilder.IComparableNotDefined;
62 override public void Copy(int recordNo1, int recordNo2) {
63 values[recordNo2] = values[recordNo1];
66 override public Object Get(int record) {
67 return values[record];
70 override public bool IsNull(int record) {
71 return (values[record].IsNull);
74 override public void Set(int record, Object value) {
75 if ((value == DBNull.Value) || (value == null)){
76 values[record] = SqlChars.Null;
79 values[record] = (SqlChars)value;
83 override public void SetCapacity(int capacity) {
84 SqlChars[] newValues = new SqlChars[capacity];
86 Array.Copy(values, 0, newValues, 0, Math.Min(capacity, values.Length));
91 override public object ConvertXmlToObject(string s) {
92 SqlString newValue = new SqlString();
94 string tempStr =string.Concat("<col>", s, "</col>"); // this is done since you can give fragmet to reader, bug 98767
95 StringReader strReader = new StringReader(tempStr);
97 IXmlSerializable tmp = newValue;
99 using (XmlTextReader xmlTextReader = new XmlTextReader(strReader)) {
100 tmp.ReadXml(xmlTextReader);
102 return (new SqlChars((SqlString)tmp));
105 override public string ConvertObjectToXml(object value) {
106 Debug.Assert(!DataStorage.IsObjectNull(value), "we shouldn't have null here");
107 Debug.Assert((value.GetType() == typeof(SqlChars)), "wrong input type");
109 StringWriter strwriter = new StringWriter(FormatProvider);
111 using (XmlTextWriter xmlTextWriter = new XmlTextWriter (strwriter)) {
112 ((IXmlSerializable)value).WriteXml(xmlTextWriter);
114 return (strwriter.ToString ());
117 override protected object GetEmptyStorage(int recordCount) {
118 return new SqlChars[recordCount];
121 override protected void CopyValue(int record, object store, BitArray nullbits, int storeIndex) {
122 SqlChars[] typedStore = (SqlChars[]) store;
123 typedStore[storeIndex] = values[record];
124 nullbits.Set(storeIndex, IsNull(record));
127 override protected void SetStorage(object store, BitArray nullbits) {
128 values = (SqlChars[]) store;
129 //SetNullStorage(nullbits);