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 public class DbConnectionOptions {
45 internal NameValueCollection options;
46 internal string normalizedConnectionString;
52 internal DbConnectionOptions ()
57 protected internal DbConnectionOptions (DbConnectionOptions connectionOptions)
59 options = connectionOptions.options;
63 public DbConnectionOptions (string connectionString)
65 options = new NameValueCollection ();
66 ParseConnectionString (connectionString);
70 public DbConnectionOptions (string connectionString, Hashtable synonyms, bool useFirstKeyValuePair)
71 : this (connectionString)
75 #endregion // Constructors
81 get { throw new NotImplementedException (); }
84 public string this [string keyword] {
85 get { return options [keyword]; }
88 public ICollection Keys {
89 get { return options.Keys; }
92 #endregion // Properties
97 protected void BuildConnectionString (StringBuilder builder, string[] withoutOptions, string insertValue)
99 throw new NotImplementedException ();
102 public bool ContainsKey (string keyword)
104 return (options.Get (keyword) != null);
107 public bool ConvertValueToBoolean (string keyname, bool defaultvalue)
109 if (ContainsKey (keyname))
110 return Boolean.Parse (this [keyname].Trim ());
114 public int ConvertValueToInt32 (string keyname, int defaultvalue)
116 if (ContainsKey (keyname))
117 return Int32.Parse (this [keyname].Trim ());
122 public bool ConvertValueToIntegratedSecurity ()
124 throw new NotImplementedException ();
127 public string ConvertValueToString (string keyname, string defaultValue)
129 if (ContainsKey (keyname))
130 return this [keyname];
135 protected internal virtual PermissionSet CreatePermissionSet ()
137 throw new NotImplementedException ();
141 protected internal virtual string Expand ()
143 throw new NotImplementedException ();
147 public static string RemoveKeyValuePairs (string connectionString, string[] keynames)
149 throw new NotImplementedException ();
153 public string UsersConnectionString (bool hisPasswordPwd)
155 throw new NotImplementedException ();
158 internal void ParseConnectionString (string connectionString)
160 if (connectionString.Length == 0)
163 connectionString += ";";
165 bool inQuote = false;
166 bool inDQuote = false;
169 string name = String.Empty;
170 string value = String.Empty;
171 StringBuilder sb = new StringBuilder ();
173 for (int i = 0; i < connectionString.Length; i += 1) {
174 char c = connectionString [i];
176 if (i == connectionString.Length - 1)
179 peek = connectionString [i + 1];
185 else if (peek.Equals (c)) {
195 else if (peek.Equals (c)) {
200 inDQuote = !inDQuote;
203 if (inDQuote || inQuote)
206 if (name != String.Empty && name != null) {
207 value = sb.ToString ();
208 // FIXME - KeywordLookup is an NOP
209 // options [KeywordLookup (name.Trim ())] = value;
210 options [name.Trim ()] = value;
214 value = String.Empty;
215 sb = new StringBuilder ();
219 if (inDQuote || inQuote || !inName)
221 else if (peek.Equals (c)) {
226 name = sb.ToString ();
227 sb = new StringBuilder ();
232 if (inQuote || inDQuote)
234 else if (sb.Length > 0 && !peek.Equals (';'))
243 StringBuilder normalized = new StringBuilder ();
244 ArrayList keys = new ArrayList ();
245 keys.AddRange (Keys);
247 foreach (string key in keys)
249 string entry = String.Format ("{0}=\"{1}\";", key, this [key].Replace ("\"", "\"\""));
250 normalized.Append (entry);
252 normalizedConnectionString = normalized.ToString ();
255 #endregion // Methods