2 // System.Data.Common.DbConnectionOptions
3 // adapted from older (pre beta1) DbConnectionString
6 // Tim Coleman (tim@timcoleman.com)
7 // Sebastien Pouliot <sebastien@ximian.com>
9 // Copyright (C) Tim Coleman, 2003
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Collections.Specialized;
36 using System.Security;
39 namespace System.Data.Common {
41 internal class DbConnectionOptions {
45 internal NameValueCollection options;
46 internal string normalizedConnectionString;
52 internal DbConnectionOptions ()
56 protected internal DbConnectionOptions (DbConnectionOptions connectionOptions)
58 options = connectionOptions.options;
61 public DbConnectionOptions (string connectionString)
63 options = new NameValueCollection ();
64 ParseConnectionString (connectionString);
68 public DbConnectionOptions (string connectionString, Hashtable synonyms, bool useFirstKeyValuePair)
69 : this (connectionString)
73 #endregion // Constructors
79 get { throw new NotImplementedException (); }
82 public string this [string keyword] {
83 get { return options [keyword]; }
86 public ICollection Keys {
87 get { return options.Keys; }
90 #endregion // Properties
95 protected void BuildConnectionString (StringBuilder builder, string[] withoutOptions, string insertValue)
97 throw new NotImplementedException ();
100 public bool ContainsKey (string keyword)
102 return (options.Get (keyword) != null);
105 public bool ConvertValueToBoolean (string keyname, bool defaultvalue)
107 if (ContainsKey (keyname))
108 return Boolean.Parse (this [keyname].Trim ());
112 public int ConvertValueToInt32 (string keyname, int defaultvalue)
114 if (ContainsKey (keyname))
115 return Int32.Parse (this [keyname].Trim ());
120 public bool ConvertValueToIntegratedSecurity ()
122 throw new NotImplementedException ();
125 public string ConvertValueToString (string keyname, string defaultValue)
127 if (ContainsKey (keyname))
128 return this [keyname];
133 protected internal virtual PermissionSet CreatePermissionSet ()
135 throw new NotImplementedException ();
139 protected internal virtual string Expand ()
141 throw new NotImplementedException ();
145 public static string RemoveKeyValuePairs (string connectionString, string[] keynames)
147 throw new NotImplementedException ();
151 public string UsersConnectionString (bool hisPasswordPwd)
153 throw new NotImplementedException ();
156 internal void ParseConnectionString (string connectionString)
158 if (connectionString.Length == 0)
161 connectionString += ";";
163 bool inQuote = false;
164 bool inDQuote = false;
167 string name = String.Empty;
168 string value = String.Empty;
169 StringBuilder sb = new StringBuilder ();
171 for (int i = 0; i < connectionString.Length; i += 1) {
172 char c = connectionString [i];
174 if (i == connectionString.Length - 1)
177 peek = connectionString [i + 1];
183 else if (peek.Equals (c)) {
193 else if (peek.Equals (c)) {
198 inDQuote = !inDQuote;
201 if (inDQuote || inQuote)
204 if (name != String.Empty && name != null) {
205 value = sb.ToString ();
206 // FIXME - KeywordLookup is an NOP
207 // options [KeywordLookup (name.Trim ())] = value;
208 options [name.Trim ()] = value;
212 value = String.Empty;
213 sb = new StringBuilder ();
217 if (inDQuote || inQuote || !inName)
219 else if (peek.Equals (c)) {
224 name = sb.ToString ();
225 sb = new StringBuilder ();
230 if (inQuote || inDQuote)
232 else if (sb.Length > 0 && !peek.Equals (';'))
241 StringBuilder normalized = new StringBuilder ();
242 ArrayList keys = new ArrayList ();
243 keys.AddRange (Keys);
245 foreach (string key in keys)
247 string entry = String.Format ("{0}=\"{1}\";", key, this [key].Replace ("\"", "\"\""));
248 normalized.Append (entry);
250 normalizedConnectionString = normalized.ToString ();
253 #endregion // Methods