File: SqlServer2KCompatibilityCheck.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (60 lines) | stat: -rw-r--r-- 2,335 bytes parent folder | download | duplicates (7)
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
using System;
using System.Collections.ObjectModel;
using System.Text;

namespace System.Data.Linq.SqlClient {

    /// <summary>
    /// Methods for checking whethe a query was compatible with the
    /// server it will be sent to.
    /// </summary>
    static internal class SqlServerCompatibilityCheck {

        /// <summary>
        /// Private visitor class checks each node for compatibility annotations.
        /// </summary>
        private class Visitor : SqlVisitor {

            private SqlProvider.ProviderMode provider;
            internal SqlNodeAnnotations annotations;

            internal Visitor(SqlProvider.ProviderMode provider) {
                this.provider = provider;
            }

            /// <summary>
            /// The reasons why this query is not 2K compatible.
            /// </summary>
            internal Collection<string> reasons = new Collection<string>();

            internal override SqlNode Visit(SqlNode node) {
                if (annotations.NodeIsAnnotated(node)) {
                    foreach (SqlNodeAnnotation annotation in annotations.Get(node)) {
                        SqlServerCompatibilityAnnotation ssca = annotation as SqlServerCompatibilityAnnotation;
                        if (ssca != null && ssca.AppliesTo(provider)) {
                            reasons.Add(annotation.Message);
                        }
                    }
                }
                return base.Visit(node);
            }
        }

        /// <summary>
        /// Checks whether the given node is supported on the given server.
        /// </summary>
        internal static void ThrowIfUnsupported(SqlNode node, SqlNodeAnnotations annotations, SqlProvider.ProviderMode provider) {
            // Check to see whether there's at least one SqlServerCompatibilityAnnotation.
            if (annotations.HasAnnotationType(typeof(SqlServerCompatibilityAnnotation))) {
                Visitor visitor = new Visitor(provider);
                visitor.annotations = annotations;
                visitor.Visit(node);

                // If any messages were recorded, then throw an exception.
                if (visitor.reasons.Count > 0) {
                    throw Error.ExpressionNotSupportedForSqlServerVersion(visitor.reasons);
                }
            }
        }
    }
}