2 // System.Data.Odbc.OdbcConnectionStringBuilder
5 // Nidhi Rawal (rawalnidhi_rawal@yahoo.com)
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Collections.Generic;
35 using System.Data.Common;
36 using System.Data.Odbc;
37 using System.Reflection;
40 namespace System.Data.Odbc
42 [DefaultProperty ("Driver")]
43 [TypeConverter ("System.Data.Odbc.OdbcConnectionStringBuilder+OdbcConnectionStringBuilderConverter, " + Consts.AssemblySystem_Data)]
44 public sealed class OdbcConnectionStringBuilder : DbConnectionStringBuilder
53 public OdbcConnectionStringBuilder () : base (true)
57 public OdbcConnectionStringBuilder (string connectionString) : base (true)
59 if (connectionString == null) {
60 base.ConnectionString = string.Empty;
64 base.ConnectionString = connectionString;
67 #endregion // Constructors
71 public override Object this [string keyword] {
74 throw new ArgumentNullException ("keyword");
75 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0)
77 if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0)
79 return base [keyword];
88 throw new ArgumentNullException ("keyword");
90 string text_value = value.ToString ();
92 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0) {
95 } else if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0) {
97 } else if (value.ToString ().IndexOf (';') != -1) {
98 text_value = "{" + text_value + "}";
100 base [keyword] = value;
104 public override ICollection Keys {
106 List<string> keys = new List<string> ();
110 ICollection base_keys = base.Keys;
111 foreach (string keyword in base_keys) {
112 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0)
114 if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0)
119 string [] final = new string [keys.Count];
125 [DisplayName ("Driver")]
126 [RefreshProperties (RefreshProperties.All)]
127 public string Driver {
135 throw new ArgumentNullException ("Driver");
138 if (value.Length > 0) {
139 int startBrace = value.IndexOf ('{');
140 int endBrace = value.IndexOf ('}');
141 if (startBrace == -1 || endBrace == -1)
142 value = "{" + value + "}";
143 else if (startBrace > 0 || endBrace < (value.Length - 1))
144 value = "{" + value + "}";
146 base ["Driver"] = value;
150 [DisplayName ("Dsn")]
151 [RefreshProperties (RefreshProperties.All)]
160 throw new ArgumentNullException ("Dsn");
166 #endregion // Properties
170 public override bool ContainsKey (string keyword)
173 throw new ArgumentNullException ("keyword");
174 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0)
176 if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0)
178 return base.ContainsKey (keyword);
181 public override bool Remove (string keyword)
184 throw new ArgumentNullException ("keyword");
185 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0)
186 driver = string.Empty;
187 else if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0)
189 return base.Remove (keyword);
192 public override void Clear ()
199 public override bool TryGetValue (string keyword, out Object value)
201 if (keyword == null )
202 throw new ArgumentNullException ("keyword");
203 bool found = base.TryGetValue (keyword, out value);
206 if (string.Compare (keyword, "Driver", StringComparison.InvariantCultureIgnoreCase) == 0) {
207 value = string.Empty;
209 } else if (string.Compare (keyword, "Dsn", StringComparison.InvariantCultureIgnoreCase) == 0) {
210 value = string.Empty;
216 #endregion // Methods
219 #endif // NET_2_0 using