1 //------------------------------------------------------------------------------
2 // <copyright file="SQLGuidStorage.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
{
13 using System
.Data
.SqlTypes
;
14 using System
.Diagnostics
;
15 using System
.Globalization
;
17 using System
.Xml
.Serialization
;
18 using System
.Collections
;
20 internal sealed class SqlGuidStorage
: DataStorage
{
22 private SqlGuid
[] values
;
24 public SqlGuidStorage(DataColumn column
)
25 : base(column
, typeof(SqlGuid
), SqlGuid
.Null
, SqlGuid
.Null
, StorageType
.SqlGuid
) {
28 override public Object
Aggregate(int[] records
, AggregateType kind
) {
31 case AggregateType
.First
:
32 if (records
.Length
> 0) {
33 return values
[records
[0]];
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(SqlGuid
));
49 throw ExceptionBuilder
.AggregateException(kind
, DataType
);
52 override public int Compare(int recordNo1
, int recordNo2
) {
53 return values
[recordNo1
].CompareTo(values
[recordNo2
]);
56 override public int CompareValueTo(int recordNo
, Object
value) {
57 return values
[recordNo
].CompareTo((SqlGuid
)value);
60 override public object ConvertValue(object value) {
62 return SqlConvert
.ConvertToSqlGuid(value);
67 override public void Copy(int recordNo1
, int recordNo2
) {
68 values
[recordNo2
] = values
[recordNo1
];
71 override public Object
Get(int record
) {
72 return values
[record
];
75 override public bool IsNull(int record
) {
76 return (values
[record
].IsNull
);
79 override public void Set(int record
, Object
value) {
80 values
[record
] = SqlConvert
.ConvertToSqlGuid(value);
83 override public void SetCapacity(int capacity
) {
84 SqlGuid
[] newValues
= new SqlGuid
[capacity
];
86 Array
.Copy(values
, 0, newValues
, 0, Math
.Min(capacity
, values
.Length
));
91 override public object ConvertXmlToObject(string s
) {
92 SqlGuid newValue
= new SqlGuid();
93 string tempStr
=string.Concat("<col>", s
, "</col>"); // this is done since you can give fragmet to reader, bug 98767
94 StringReader strReader
= new StringReader(tempStr
);
96 IXmlSerializable tmp
= newValue
;
98 using (XmlTextReader xmlTextReader
= new XmlTextReader(strReader
)) {
99 tmp
.ReadXml(xmlTextReader
);
101 return ((SqlGuid
)tmp
);
104 override public string ConvertObjectToXml(object value) {
105 Debug
.Assert(!DataStorage
.IsObjectNull(value), "we shouldn't have null here");
106 Debug
.Assert((value.GetType() == typeof(SqlGuid
)), "wrong input type");
108 StringWriter strwriter
= new StringWriter(FormatProvider
);
110 using (XmlTextWriter xmlTextWriter
= new XmlTextWriter (strwriter
)) {
111 ((IXmlSerializable
)value).WriteXml(xmlTextWriter
);
113 return (strwriter
.ToString ());
116 override protected object GetEmptyStorage(int recordCount
) {
117 return new SqlGuid
[recordCount
];
120 override protected void CopyValue(int record
, object store
, BitArray nullbits
, int storeIndex
) {
121 SqlGuid
[] typedStore
= (SqlGuid
[]) store
;
122 typedStore
[storeIndex
] = values
[record
];
123 nullbits
.Set(storeIndex
, IsNull(record
));
126 override protected void SetStorage(object store
, BitArray nullbits
) {
127 values
= (SqlGuid
[]) store
;
128 //SetNullStorage(nullbits);