Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExpressionNode.cs « Filter « Data « System « System.Data « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 049e98aa8f2dcb88dd1c464690cbc387cf482b3a (plain)
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
//------------------------------------------------------------------------------
// <copyright file="ExpressionNode.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 {
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Data.SqlTypes;

    internal abstract class ExpressionNode {
        private DataTable _table;

        protected ExpressionNode(DataTable table) {
            _table = table;
        }

        internal IFormatProvider FormatProvider {
            get {
                return ((null != _table) ? _table.FormatProvider : System.Globalization.CultureInfo.CurrentCulture);
            }
        }

        internal virtual bool IsSqlColumn{
            get{
                return false;
            }
        }

        protected DataTable table {
            get { return _table; }
        }

        protected void BindTable(DataTable table) {
            // when the expression is created, DataColumn may not be associated with a table yet
            _table = table;
        }

        internal abstract void Bind(DataTable table, List<DataColumn> list);
        internal abstract object Eval();
        internal abstract object Eval(DataRow row, DataRowVersion version);
        internal abstract object Eval(int[] recordNos);
        internal abstract bool IsConstant();
        internal abstract bool IsTableConstant();
        internal abstract bool HasLocalAggregate();
        internal abstract bool HasRemoteAggregate();
        internal abstract ExpressionNode Optimize();
        internal virtual bool DependsOn(DataColumn column) {
            return false;
        }

        internal static bool IsInteger(StorageType type) {
            return(type == StorageType.Int16 ||
                type == StorageType.Int32 ||
                type == StorageType.Int64 ||
                type == StorageType.UInt16 ||
                type == StorageType.UInt32 ||
                type == StorageType.UInt64 ||
                type == StorageType.SByte ||
                type == StorageType.Byte);
        }

        internal static bool IsIntegerSql(StorageType type) {
            return(type == StorageType.Int16 ||
                type == StorageType.Int32 ||
                type == StorageType.Int64 ||
                type == StorageType.UInt16 ||
                type == StorageType.UInt32 ||
                type == StorageType.UInt64 ||
                type == StorageType.SByte  ||
                type == StorageType.Byte ||
                type == StorageType.SqlInt64 ||
                type == StorageType.SqlInt32 ||
                type == StorageType.SqlInt16 ||
                type == StorageType.SqlByte);
        }

        internal static bool IsSigned(StorageType type) {
            return(type == StorageType.Int16 ||
                type == StorageType.Int32 ||
                type == StorageType.Int64 ||
                type == StorageType.SByte ||
                IsFloat(type));
        }

        internal static bool IsSignedSql(StorageType type) {
            return(type == StorageType.Int16 || // IsSigned(type)
                type == StorageType.Int32 ||
                type == StorageType.Int64 ||
                type == StorageType.SByte ||
                type == StorageType.SqlInt64 ||
                type == StorageType.SqlInt32 ||
                type == StorageType.SqlInt16 ||
                IsFloatSql(type));
        }

        internal static bool IsUnsigned(StorageType type) {
            return(type == StorageType.UInt16 ||
                   type == StorageType.UInt32 ||
                   type == StorageType.UInt64 ||
                   type == StorageType.Byte);
        }

        internal static bool IsUnsignedSql(StorageType type) {
            return(type == StorageType.UInt16 ||
                   type == StorageType.UInt32 ||
                   type == StorageType.UInt64 ||
                   type == StorageType.SqlByte ||// SqlByte represents an 8-bit unsigned integer, in the range of 0 through 255,
                   type == StorageType.Byte);
        }

        internal static bool IsNumeric(StorageType type) {
            return(IsFloat(type) ||
                   IsInteger(type));
        }

        internal static bool IsNumericSql(StorageType type) {
            return(IsFloatSql(type) ||
                   IsIntegerSql(type));
        }

        internal static bool IsFloat(StorageType type) {
            return(type == StorageType.Single ||
                type == StorageType.Double ||
                type == StorageType.Decimal);
        }

        internal static bool IsFloatSql(StorageType type) {
            return(type == StorageType.Single ||
                type == StorageType.Double ||
                type == StorageType.Decimal ||
                type == StorageType.SqlDouble ||
                type == StorageType.SqlDecimal || // I expect decimal to be Integer!
                type == StorageType.SqlMoney ||   // if decimal is here, this should be definitely here!
                type == StorageType.SqlSingle);
        }

    }
}