File: StringStorage.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (188 lines) | stat: -rw-r--r-- 6,393 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//------------------------------------------------------------------------------
// <copyright file="StringStorage.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
// <owner current="false" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------

namespace System.Data.Common {
    using System;
    using System.Diagnostics;
    using System.Globalization;
    using System.Data.SqlTypes;
    using System.Collections;

    // The string storage does not use BitArrays in DataStorage
    internal sealed class StringStorage : DataStorage {

        private String[] values;

        public StringStorage(DataColumn column)
        : base(column, typeof(String), String.Empty, StorageType.String) {
        }

        override public Object Aggregate(int[] recordNos, AggregateType kind) {
            int i;
            switch (kind) {
                case AggregateType.Min:
                    int min = -1;
                    for (i = 0; i < recordNos.Length; i++) {
                        if (IsNull(recordNos[i]))
                            continue;
                        min = recordNos[i];
                        break;
                    }
                    if (min >= 0) {
                        for (i = i+1; i < recordNos.Length; i++) {
                            if (IsNull(recordNos[i]))
                                continue;
                            if (Compare(min, recordNos[i]) > 0) {
                                min = recordNos[i];
                            }
                        }
                        return Get(min);
                    }
                    return NullValue;

                case AggregateType.Max:
                    int max = -1;
                    for (i = 0; i < recordNos.Length; i++) {
                        if (IsNull(recordNos[i]))
                            continue;
                        max = recordNos[i];
                        break;
                    }
                    if (max >= 0) {
                        for (i = i+1; i < recordNos.Length; i++) {
                            if (Compare(max, recordNos[i]) < 0) {
                                max = recordNos[i];
                            }
                        }
                        return Get(max);
                    }
                    return NullValue;

                case AggregateType.Count:
                    int count = 0;
                    for (i = 0; i < recordNos.Length; i++) {
                        Object value = values[recordNos[i]];
                        if (value != null)
                            count++;
                    }
                    return count;
            }
            throw ExceptionBuilder.AggregateException(kind, DataType);
        }

        override public int Compare(int recordNo1, int recordNo2) {
            string valueNo1 = values[recordNo1];
            string valueNo2 = values[recordNo2];

            if ((Object)valueNo1 == (Object)valueNo2)
                return 0;

            if (valueNo1 == null)
                return -1;
            if (valueNo2 == null)
                return 1;

            return Table.Compare(valueNo1, valueNo2);
        }

        override public int CompareValueTo(int recordNo, Object value) {
            Debug.Assert(recordNo != -1, "Invalid (-1) parameter: 'recordNo'");
            Debug.Assert(null != value, "null value");
            string valueNo1 = values[recordNo];

            if (null == valueNo1) {
                if (NullValue == value) {
                    return 0;
                }
                else {
                    return -1;
                }
            }
            else if (NullValue == value) {
                return 1;
            }
            return Table.Compare(valueNo1, (string)value);
        }

        public override object ConvertValue(object value) {
            if (NullValue != value) {
                if (null != value) {
                    value = value.ToString();
                }
                else {
                    value = NullValue;
                }
            }
            return value;
        }

        override public void Copy(int recordNo1, int recordNo2) {
            values[recordNo2] = values[recordNo1];
        }

        override public Object Get(int recordNo) {
            String value = values[recordNo];

            if (null != value) {
                return value;
            }
            return NullValue;
        }

        override public int GetStringLength(int record) {
            string value = values[record];
            return ((null != value) ? value.Length : 0);
        }

        override public bool IsNull(int record) {
            return (null == values[record]);
        }

        override public void Set(int record, Object value) {
            System.Diagnostics.Debug.Assert(null != value, "null value");
            if (NullValue == value) {
                values[record] = null;
            }
            else {
                values[record] = value.ToString();
            }
        }

        override public void SetCapacity(int capacity) {
            string[] newValues = new string[capacity];
            if (values != null) {
                Array.Copy(values, 0, newValues, 0, Math.Min(capacity, values.Length));
            }
            values = newValues;
        }

        override public object ConvertXmlToObject(string s) {
            return s;
        }

        override public string ConvertObjectToXml(object value) {
            return (string)value;
        }

        override protected object GetEmptyStorage(int recordCount) {
            return new String[recordCount];
        }

        override protected void CopyValue(int record, object store, BitArray nullbits, int storeIndex) {
            String[] typedStore = (String[]) store;
            typedStore[storeIndex] = values[record];
            nullbits.Set(storeIndex, IsNull(record));
        }

        override protected void SetStorage(object store, BitArray nullbits) {
            values = (String[]) store;
 //           SetNullStorage(nullbits);
        }
    }
}