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

OdbcConnectionString.cs « Odbc « Data « System « System.Data « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8214495463e481863238d6fc33c9a1869509f7f5 (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
//------------------------------------------------------------------------------
// <copyright file="OdbcConnectionString.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">[....]</owner>
//------------------------------------------------------------------------------

namespace System.Data.Odbc {

    using System;
    using System.Collections;
    using System.Data;
    using System.Data.Common;
    using System.Security;
    using System.Security.Permissions;
    using System.Text;

    internal sealed class OdbcConnectionString : DbConnectionOptions {
        // instances of this class are intended to be immutable, i.e readonly
        // used by pooling classes so it is much easier to verify correctness
        // when not worried about the class being modified during execution

        private static class KEY {
            internal const string SaveFile                  = "savefile";
        }

        private readonly string _expandedConnectionString;        

        internal OdbcConnectionString(string connectionString, bool validate) : base(connectionString, null, true) {            
            if (!validate) {
                string filename = null;
                int position = 0;
                _expandedConnectionString = ExpandDataDirectories(ref filename, ref position);
            }
            if (validate || (null == _expandedConnectionString)) {
                // do not check string length if it was expanded because the final result may be shorter than the original
                if ((null != connectionString) && (ODBC32.MAX_CONNECTION_STRING_LENGTH < connectionString.Length)) { // MDAC 83536
                    throw ODBC.ConnectionStringTooLong();
                }
            }
        }

        protected internal override System.Security.PermissionSet CreatePermissionSet() {
            System.Security.PermissionSet permissionSet;
            if (ContainsKey(KEY.SaveFile)) {
                permissionSet = new NamedPermissionSet("FullTrust");
            }
            else {
                permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                permissionSet.AddPermission(new OdbcPermission(this));
            }
            return permissionSet;
        }

        protected internal override string Expand() {
            if (null != _expandedConnectionString) {
                return _expandedConnectionString;
            }
            else {
                return base.Expand();
            }
        }
    }
}