DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DeveelDbConnectionStringBuilder.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Data.Common;
22 using System.Globalization;
23 
24 using Deveel.Data.Sql;
25 
26 namespace Deveel.Data.Client {
27  [DefaultProperty("DataSource")]
28  public sealed class DeveelDbConnectionStringBuilder : DbConnectionStringBuilder {
29  public DeveelDbConnectionStringBuilder(string connectionString) {
30  InitToDefault();
31  ConnectionString = connectionString;
32  }
33 
35  : this(String.Empty) {
36  }
37 
39  defaults = new Dictionary<string, object>();
40  defaults.Add(HostKey, DefaultHost);
41  defaults.Add(PortKey, DefaultPort);
42  defaults.Add(DatabaseKey, DefaultDatabase);
43  defaults.Add(UserNameKey, DefaultUserName);
44  defaults.Add(PasswordKey, DefaultPassword);
45  defaults.Add(SchemaKey, DefaultSchema);
46  defaults.Add(PathKey, DefaultPath);
47  defaults.Add(CreateKey, DefaultCreate);
48  defaults.Add(BootOrCreateKey, DefaultBootOrCreate);
49  defaults.Add(ParameterStyleKey, DefaultParameterStyle);
50  defaults.Add(VerboseColumnNamesKey, DefaultVerboseColumnName);
51  defaults.Add(PersistSecurityInfoKey, DefaultPersistSecurityInfo);
52  defaults.Add(RowCacheSizeKey, DefaultRowCacheSize);
53  defaults.Add(MaxCacheSizeKey, DefaultMaxCacheSize);
54  defaults.Add(FetchSizeKey, DefaultFetchSize);
55  defaults.Add(MaxFetchSizeKey, DefaultMaxFetchSize);
56  defaults.Add(AutoCommitKey, DefaultAutoCommit);
57  defaults.Add(QueryTimeoutKey, DefaultQueryTimeout);
58 
59  keymaps = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
60  keymaps[HostKey.ToUpper()] = HostKey;
61  keymaps["ADDRESS"] = HostKey;
62  keymaps["SERVER"] = HostKey;
63  keymaps[PortKey.ToUpper()] = PortKey;
64  keymaps[DatabaseKey.ToUpper()] = DatabaseKey;
65  keymaps["CATALOG"] = DatabaseKey;
66  keymaps["INITIAL CATALOG"] = DatabaseKey;
67  keymaps["DB"] = DatabaseKey;
68  keymaps[SchemaKey.ToUpper()] = SchemaKey;
69  keymaps["DEFAULT SCHEMA"] = SchemaKey;
70  keymaps[PathKey.ToUpper()] = PathKey;
71  keymaps["DATA PATH"] = PathKey;
72  keymaps["DATABASE PATH"] = PathKey;
73  keymaps["DATAPATH"] = PathKey;
74  keymaps["DATABASEPATH"] = PathKey;
75  keymaps[CreateKey.ToUpper()] = CreateKey;
76  keymaps[BootOrCreateKey] = BootOrCreateKey;
77  keymaps["BOOT OR CREATE"] = BootOrCreateKey;
78  keymaps["CREATE OR BOOT"] = BootOrCreateKey;
79  keymaps["CREATEORBOOT"] = BootOrCreateKey;
80  keymaps[CreateKey.ToUpper()] = CreateKey;
81  keymaps["CREATE DATABASE"] = CreateKey;
82  keymaps[UserNameKey.ToUpper()] = UserNameKey;
83  keymaps["USER"] = UserNameKey;
84  keymaps["USER NAME"] = UserNameKey;
85  keymaps["USER ID"] = UserNameKey;
86  keymaps["USERID"] = UserNameKey;
87  keymaps["UID"] = UserNameKey;
88  keymaps[PasswordKey.ToUpper()] = PasswordKey;
89  keymaps["PASS"] = PasswordKey;
90  keymaps["PWD"] = PasswordKey;
91  keymaps["SECRET"] = PasswordKey;
92  keymaps[ParameterStyleKey.ToUpper()] = ParameterStyleKey;
93  keymaps["PARAMSTYLE"] = ParameterStyleKey;
94  keymaps["PARAMETER STYLE"] = ParameterStyleKey;
95  keymaps["USEPARMAMETER"] = ParameterStyleKey;
96  keymaps["USE PARAMETER"] = ParameterStyleKey;
97  keymaps[VerboseColumnNamesKey.ToUpper()] = VerboseColumnNamesKey;
98  keymaps["VERBOSE COLUMNS"] = VerboseColumnNamesKey;
99  keymaps["VERBOSE COLUMN NAMES"] = VerboseColumnNamesKey;
100  keymaps["VERBOSECOLUMNS"] = VerboseColumnNamesKey;
101  keymaps["COLUMNS VERBOSE"] = VerboseColumnNamesKey;
102  keymaps[PersistSecurityInfoKey.ToUpper()] = PersistSecurityInfoKey;
103  keymaps["PERSIST SECURITY INFO"] = PersistSecurityInfoKey;
104  keymaps[RowCacheSizeKey.ToUpper()] = RowCacheSizeKey;
105  keymaps["ROW CACHE SIZE"] = RowCacheSizeKey;
106  keymaps["CACHE SIZE"] = RowCacheSizeKey;
107  keymaps[MaxCacheSizeKey.ToUpper()] = MaxCacheSizeKey;
108  keymaps["MAX CACHE SIZE"] = MaxCacheSizeKey;
109  keymaps["MAX CACHE"] = MaxCacheSizeKey;
110  keymaps[QueryTimeoutKey.ToUpper()] = QueryTimeoutKey;
111  keymaps["QUERY TIMEOUT"] = QueryTimeoutKey;
112  keymaps[IgnoreIdentifiersCaseKey.ToUpper()] = IgnoreIdentifiersCaseKey;
113  keymaps["IGNORE CASE"] = IgnoreIdentifiersCaseKey;
114  keymaps["IGNORE ID CASE"] = IgnoreIdentifiersCaseKey;
115  keymaps["ID CASE IGNORED"] = IgnoreIdentifiersCaseKey;
116  keymaps[StrictGetValueKey.ToUpper()] = StrictGetValueKey;
117  keymaps["STRICT"] = StrictGetValueKey;
118  keymaps["STRICT GETVALUE"] = StrictGetValueKey;
119  keymaps["STRICT VALUE"] = StrictGetValueKey;
120  keymaps["STRICTVALUE"] = StrictGetValueKey;
121  keymaps[FetchSizeKey.ToUpper()] = FetchSizeKey;
122  keymaps["FETCH SIZE"] = FetchSizeKey;
123  keymaps["ROW COUNT"] = FetchSizeKey;
124  keymaps["ROWCOUNT"] = FetchSizeKey;
125  keymaps[MaxFetchSizeKey.ToUpper()] = MaxFetchSizeKey;
126  keymaps["MAX FETCH SIZE"] = MaxFetchSizeKey;
127  keymaps["MAXFETCHSIZE"] = MaxFetchSizeKey;
128  keymaps["MAX ROW COUNT"] = MaxFetchSizeKey;
129  keymaps["MAX ROWCOUNT"] = MaxFetchSizeKey;
130  keymaps["MAXROWCOUNT"] = MaxFetchSizeKey;
131  keymaps[AutoCommitKey.ToUpper()] = AutoCommitKey;
132  keymaps["AUTOCOMMIT"] = AutoCommitKey;
133  keymaps["AUTO-COMMIT"] = AutoCommitKey;
134  keymaps["AUTO_COMMIT"] = AutoCommitKey;
135  keymaps["AUTO COMMIT"] = AutoCommitKey;
136  keymaps["COMMIT AUTO"] = AutoCommitKey;
137  keymaps["COMMIT_AUTO"] = AutoCommitKey;
138  keymaps["COMMITAUTO"] = AutoCommitKey;
139  keymaps["COMMIT-AUTO"] = AutoCommitKey;
140  keymaps["COMMIT"] = AutoCommitKey;
141  }
142 
143  private const string HostKey = "Host";
144  private const string PortKey = "Port";
145  private const string DatabaseKey = "Database";
146  private const string UserNameKey = "UserName";
147  private const string PasswordKey = "Password";
148  private const string SchemaKey = "Schema";
149  private const string PathKey = "Path";
150  private const string CreateKey = "Create";
151  private const string BootOrCreateKey = "BootOrCreate";
152  private const string ParameterStyleKey = "ParameterStyle";
153  private const string VerboseColumnNamesKey = "VerboseColumnNames";
154  private const string PersistSecurityInfoKey = "PersistSecurityInfo";
155  private const string RowCacheSizeKey = "RowCacheSize";
156  private const string MaxCacheSizeKey = "MaxCacheSize";
157  private const string QueryTimeoutKey = "QueryTimeout";
158  private const string IgnoreIdentifiersCaseKey = "IgnoreIdentifiersCase";
159  private const string StrictGetValueKey = "StrictGetValue";
160  private const string FetchSizeKey = "FetchSize";
161  private const string MaxFetchSizeKey = "MaxFetchSize";
162  private const string AutoCommitKey = "AutoCommit";
163 
164  private const string DefaultHost = "localhost";
165  private const int DefaultPort = 9157;
166  private const string DefaultDatabase = "";
167  private const string DefaultUserName = "";
168  private const string DefaultPassword = "";
169  private const string DefaultSchema = "";
170  private const string DefaultPath = ".";
171  private const bool DefaultCreate = false;
172  private const bool DefaultBootOrCreate = false;
173  private const QueryParameterStyle DefaultParameterStyle = QueryParameterStyle.Marker;
174  private const bool DefaultVerboseColumnName = false;
175  private const bool DefaultPersistSecurityInfo = false;
176  private const int DefaultRowCacheSize = 1024;
177  private const int DefaultMaxCacheSize = 1024 * 40;
178  private const int DefaultQueryTimeout = Int32.MaxValue;
179  private const bool DefaultIgnoreIdentifiersCase = true;
180  private const bool DefaultStrictGetValue = false;
181  private const int DefaultMaxFetchSize = 512;
182  private const int DefaultFetchSize = 32;
183  private const bool DefaultAutoCommit = true;
184 
185  private static readonly Dictionary<string, object> defaults;
186  private static readonly Dictionary<string, string> keymaps;
187 
188  private string host;
189  private int port;
190  private string database;
191  private string userName;
192  private string password;
193  private string schema;
194  private string path;
195  private bool verboseColumnNames;
197  private bool persistSecurityInfo;
198  private int rowCacheSize;
199  private int maxCacheSize;
200  private int queryTimeout;
201  private bool ignoreCase;
202  private bool create;
203  private bool bootOrCreate;
204  private bool strictGetValue;
205  private int fetchSize;
206  private int maxFetchSize;
207  private bool autoCommit;
208 
209  public override bool IsFixedSize {
210  get { return true; }
211  }
212 
213  public override object this[string keyword] {
214  get {
215  keyword = MappKey(keyword);
216  if (base.ContainsKey(keyword))
217  return base[keyword];
218  return defaults[keyword];
219  }
220  set { SetValue(keyword, value); }
221  }
222 
223  public override ICollection Keys {
224  get {
225  var keys = new List<string> {
226  HostKey,
227  PortKey,
228  DatabaseKey,
229  SchemaKey,
230  PathKey,
231  UserNameKey,
232  PasswordKey,
233  PersistSecurityInfoKey,
234  VerboseColumnNamesKey,
235  ParameterStyleKey,
236  RowCacheSizeKey,
237  MaxCacheSizeKey,
238  QueryTimeoutKey,
239  IgnoreIdentifiersCaseKey,
240  CreateKey,
241  BootOrCreateKey,
242  StrictGetValueKey,
243  FetchSizeKey,
244  MaxFetchSizeKey,
245  AutoCommitKey
246  };
247  return keys.AsReadOnly();
248  }
249  }
250 
251  public override ICollection Values {
252  get {
253  var list = new List<object> {
254  host,
255  port,
256  database,
257  schema,
258  path,
259  userName,
260  password,
261  persistSecurityInfo,
262  verboseColumnNames,
263  paramStyle,
264  rowCacheSize,
265  maxCacheSize,
266  queryTimeout,
267  ignoreCase,
268  create,
269  bootOrCreate,
270  strictGetValue,
271  fetchSize,
272  maxFetchSize,
273  autoCommit
274  };
275  return list.AsReadOnly();
276  }
277  }
278 
279  [DisplayName("Data Source")]
280  [RefreshProperties(RefreshProperties.All)]
281  public string DataSource {
282  get {
283  string dataSource = Host;
284  if (Port > 0 && Port != DefaultPort)
285  dataSource += ":" + Port;
286 
287  return dataSource;
288  }
289  set {
290  if (value == null)
291  throw new ArgumentNullException("value");
292 
293  base["Data Source"] = value;
294 
295  int index = value.IndexOf(':');
296  if (index != -1) {
297  Port = Int32.Parse(value.Substring(index));
298  value = value.Substring(0, index);
299  }
300 
301  Host = value;
302  }
303  }
304 
305  [DisplayName("Host Address")]
306  [RefreshProperties(RefreshProperties.All)]
307  public string Host {
308  get { return host; }
309  set {
310  host = value;
311  base[HostKey] = value;
312  }
313  }
314 
315  [DisplayName("Server Port")]
316  [RefreshProperties(RefreshProperties.All)]
317  public int Port {
318  get { return port; }
319  set {
320  port = value;
321  base[PortKey] = value;
322  }
323  }
324 
325  [DisplayName("Database Name")]
326  [RefreshProperties(RefreshProperties.All)]
327  public string Database {
328  get { return database; }
329  set {
330  base[DatabaseKey] = value;
331  database = value;
332  }
333  }
334 
335  [DisplayName("Schema")]
336  [RefreshProperties(RefreshProperties.All)]
337  public string Schema {
338  get { return schema; }
339  set {
340  base[SchemaKey] = value;
341  schema = value;
342  }
343  }
344 
345  [DisplayName("User Name")]
346  [RefreshProperties(RefreshProperties.All)]
347  public string UserName {
348  get { return userName; }
349  set {
350  base[UserNameKey] = value;
351  userName = value;
352  }
353  }
354 
355  [DisplayName("User Password")]
356  [PasswordPropertyText(true)]
357  [RefreshProperties(RefreshProperties.All)]
358  public string Password {
359  get { return password; }
360  set {
361  base[PasswordKey] = value;
362  password = value;
363  }
364  }
365 
366  [DisplayName("Persist Security Info")]
367  [RefreshProperties(RefreshProperties.All)]
368  public bool PersistSecurityInfo {
369  get { return persistSecurityInfo; }
370  set {
371  base[PersistSecurityInfoKey] = value;
372  persistSecurityInfo = value;
373  }
374  }
375 
376  [DisplayName("Verbose Column Names")]
377  [RefreshProperties(RefreshProperties.All)]
378  public bool VerboseColumnNames {
379  get { return verboseColumnNames; }
380  set {
381  base[VerboseColumnNamesKey] = value;
382  verboseColumnNames = value;
383  }
384  }
385 
386  [DisplayName("Parameter Style")]
387  [RefreshProperties(RefreshProperties.All)]
388  public QueryParameterStyle ParameterStyle {
389  get { return paramStyle; }
390  set {
391  base[ParameterStyleKey] = value;
392  paramStyle = value;
393  }
394  }
395 
396  [DisplayName("Data Path")]
397  [RefreshProperties(RefreshProperties.All)]
398  public string Path {
399  get { return path; }
400  set {
401  base[PathKey] = value;
402  path = value;
403  }
404  }
405 
406  [DisplayName("Row Cache Size")]
407  [RefreshProperties(RefreshProperties.All)]
408  public int RowCacheSize {
409  get { return rowCacheSize; }
410  set {
411  base[RowCacheSizeKey] = value;
412  rowCacheSize = value;
413  }
414  }
415 
416  [DisplayName("Max Cache Size")]
417  [RefreshProperties(RefreshProperties.All)]
418  public int MaxCacheSize {
419  get { return maxCacheSize; }
420  set {
421  base[MaxCacheSizeKey] = value;
422  maxCacheSize = value;
423  }
424  }
425 
426  [DisplayName("Query Timeout")]
427  [RefreshProperties(RefreshProperties.All)]
428  public int QueryTimeout {
429  get { return queryTimeout; }
430  set {
431  base[QueryTimeoutKey] = value;
432  queryTimeout = value;
433  }
434  }
435 
436  [DisplayName("Ignore Identifiers Case")]
437  [RefreshProperties(RefreshProperties.All)]
438  public bool IgnoreIdentifiersCase {
439  get { return ignoreCase; }
440  set {
441  base[IgnoreIdentifiersCaseKey] = value;
442  ignoreCase = value;
443  }
444  }
445 
446  [DisplayName("Create New Database")]
447  [RefreshProperties(RefreshProperties.All)]
448  public bool Create {
449  get { return create; }
450  set {
451  base[CreateKey] = value;
452  create = value;
453  }
454  }
455 
456  [DisplayName("Boot/Create Database")]
457  [RefreshProperties(RefreshProperties.All)]
458  public bool BootOrCreate {
459  get { return bootOrCreate; }
460  set {
461  base[BootOrCreateKey] = value;
462  bootOrCreate = value;
463  }
464  }
465 
466  [DisplayName("Strict GetValue")]
467  [RefreshProperties(RefreshProperties.All)]
468  public bool StrictGetValue {
469  get { return strictGetValue; }
470  set {
471  base[StrictGetValueKey] = value;
472  strictGetValue = value;
473  }
474  }
475 
476  [DisplayName("Fetch Size")]
477  [RefreshProperties(RefreshProperties.All)]
478  public int FetchSize {
479  get { return fetchSize; }
480  set {
481  base[FetchSizeKey] = value;
482  fetchSize = value;
483  }
484  }
485 
486  [DisplayName("Max Fetch Size")]
487  [RefreshProperties(RefreshProperties.All)]
488  public int MaxFetchSize {
489  get { return maxFetchSize; }
490  set {
491  base[MaxFetchSizeKey] = value;
492  maxFetchSize = value;
493  }
494  }
495 
496  [DisplayName("Auto-Commit")]
497  [RefreshProperties(RefreshProperties.All)]
498  public bool AutoCommit {
499  get { return autoCommit; }
500  set {
501  base[AutoCommitKey] = value;
502  autoCommit = value;
503  }
504  }
505 
506  private void InitToDefault() {
507  host = DefaultHost;
508  port = DefaultPort;
509  database = DefaultDatabase;
510  userName = DefaultUserName;
511  password = DefaultPassword;
512  schema = DefaultSchema;
513  path = DefaultPath;
514  paramStyle = DefaultParameterStyle;
515  verboseColumnNames = DefaultVerboseColumnName;
516  persistSecurityInfo = DefaultPersistSecurityInfo;
517  rowCacheSize = DefaultRowCacheSize;
518  maxCacheSize = DefaultMaxCacheSize;
519  queryTimeout = DefaultQueryTimeout;
520  ignoreCase = DefaultIgnoreIdentifiersCase;
521  create = DefaultCreate;
522  bootOrCreate = DefaultBootOrCreate;
523  strictGetValue = DefaultStrictGetValue;
524  fetchSize = DefaultFetchSize;
525  maxFetchSize = DefaultMaxFetchSize;
526  autoCommit = DefaultAutoCommit;
527  }
528 
529  private void SetValue(string key, object value) {
530  if (key == null)
531  throw new ArgumentNullException("key");
532 
533  key = MappKey(key);
534 
535  switch (key) {
536  case HostKey: {
537  if (value == null) {
538  host = DefaultHost;
539  base.Remove(key);
540  } else {
541  Host = value.ToString();
542  }
543  break;
544  }
545  case PortKey:
546  if (value == null) {
547  port = DefaultPort;
548  base.Remove(key);
549  } else {
550  Port = ToInt32(value);
551  }
552  break;
553  case DatabaseKey:
554  if (value == null) {
555  database = DefaultDatabase;
556  base.Remove(key);
557  } else {
558  Database = value.ToString();
559  }
560  break;
561  case SchemaKey:
562  if (value == null) {
563  schema = DefaultSchema;
564  base.Remove(key);
565  } else {
566  Schema = value.ToString();
567  }
568  break;
569  case PathKey:
570  if (value == null) {
571  path = DefaultPath;
572  base.Remove(key);
573  } else {
574  Path = value.ToString();
575  }
576  break;
577  case UserNameKey:
578  if (value == null) {
579  userName = DefaultUserName;
580  base.Remove(key);
581  } else {
582  UserName = value.ToString();
583  }
584  break;
585  case PasswordKey:
586  if (value == null) {
587  password = DefaultPassword;
588  base.Remove(key);
589  } else {
590  Password = value.ToString();
591  }
592  break;
593  case PersistSecurityInfoKey:
594  if (value == null) {
595  persistSecurityInfo = DefaultPersistSecurityInfo;
596  base.Remove(key);
597  } else {
598  PersistSecurityInfo = ToBoolean(value);
599  }
600  break;
601  case VerboseColumnNamesKey:
602  if (value == null) {
603  verboseColumnNames = DefaultVerboseColumnName;
604  base.Remove(key);
605  } else {
606  VerboseColumnNames = ToBoolean(value);
607  }
608  break;
609  case ParameterStyleKey:
610  if (value == null) {
611  paramStyle = DefaultParameterStyle;
612  base.Remove(key);
613  } else if (value is string) {
614  ParameterStyle = (QueryParameterStyle)Enum.Parse(typeof(QueryParameterStyle), (string)value, true);
615  } else if (value is int ||
616  value is QueryParameterStyle) {
617  ParameterStyle = (QueryParameterStyle)value;
618  }
619  break;
620  case RowCacheSizeKey:
621  if (value == null) {
622  rowCacheSize = DefaultRowCacheSize;
623  base.Remove(key);
624  } else {
625  RowCacheSize = ToInt32(value);
626  }
627  break;
628  case MaxCacheSizeKey:
629  if (value == null) {
630  maxCacheSize = DefaultMaxCacheSize;
631  base.Remove(key);
632  } else {
633  MaxCacheSize = ToInt32(value);
634  }
635  break;
636  case QueryTimeoutKey:
637  if (value == null) {
638  queryTimeout = DefaultQueryTimeout;
639  base.Remove(key);
640  } else {
641  QueryTimeout = ToInt32(value);
642  }
643  break;
644  case IgnoreIdentifiersCaseKey:
645  if (value == null) {
646  ignoreCase = DefaultIgnoreIdentifiersCase;
647  base.Remove(key);
648  } else {
649  IgnoreIdentifiersCase = ToBoolean(value);
650  }
651  break;
652  case CreateKey:
653  if (value == null) {
654  create = DefaultCreate;
655  base.Remove(key);
656  } else {
657  Create = ToBoolean(value);
658  }
659  break;
660  case BootOrCreateKey:
661  if (value == null) {
662  bootOrCreate = DefaultBootOrCreate;
663  base.Remove(key);
664  } else {
665  BootOrCreate = ToBoolean(value);
666  }
667  break;
668  case StrictGetValueKey:
669  if (value == null) {
670  strictGetValue = DefaultStrictGetValue;
671  base.Remove(key);
672  } else {
673  StrictGetValue = ToBoolean(value);
674  }
675  break;
676  case "DataSource":
677  if (value == null) {
678 
679  } else {
680  string s = value.ToString();
681  int index = s.IndexOf(':');
682  if (index != -1) {
683  string sPort = s.Substring(index + 1);
684  Host = s.Substring(0, index);
685  Port = Int32.Parse(sPort);
686  } else {
687  Host = s;
688  }
689  }
690  break;
691  case FetchSizeKey:
692  if (value == null) {
693  fetchSize = DefaultFetchSize;
694  base.Remove(FetchSizeKey);
695  } else {
696  FetchSize = ToInt32(value);
697  }
698  break;
699  case MaxFetchSizeKey:
700  if (value == null) {
701  maxFetchSize = DefaultMaxFetchSize;
702  base.Remove(MaxFetchSizeKey);
703  } else {
704  MaxFetchSize = ToInt32(value);
705  }
706  break;
707  case AutoCommitKey:
708  if (value == null) {
709  autoCommit = DefaultAutoCommit;
710  base.Remove(AutoCommitKey);
711  } else {
712  AutoCommit = ToBoolean(value);
713  }
714  break;
715  default:
716  //TODO: support additional parameters for Boot/Create process...
717  throw new ArgumentException("Key '" + key + "' is not recognized.", "key");
718  }
719  }
720 
721  private string MappKey(string key) {
722  // this is a special case for DataSource key, that is atipical
723  if (String.Equals(key, "DataSource", StringComparison.InvariantCultureIgnoreCase))
724  return "DataSource";
725 
726  string outKey;
727  if (!keymaps.TryGetValue(key, out outKey))
728  throw new ArgumentException("The connection string keyword is not supported: " + key);
729  return outKey;
730  }
731 
732  private static bool ToBoolean(object value) {
733  if (value == null)
734  throw new ArgumentException();
735 
736  if (value is bool)
737  return (bool)value;
738 
739  if (value is string) {
740  string s = value.ToString().ToUpper();
741  if (s == "YES" || s == "ENABLED" ||
742  s == "TRUE" || s == "ON")
743  return true;
744  if (s == "NO" || s == "DISABLED" ||
745  s == "FALSE" || s == "OFF")
746  return false;
747  }
748 
749  if (value is IConvertible)
750  return (value as IConvertible).ToBoolean(CultureInfo.InvariantCulture);
751 
752  throw new ArgumentException();
753  }
754 
755  private static int ToInt32(object value) {
756  if (value == null)
757  throw new ArgumentException();
758 
759  if (value is int)
760  return (int)value;
761 
762  if (value is string) {
763  string s = value.ToString();
764  return Int32.Parse(s, CultureInfo.InvariantCulture);
765  }
766 
767  if (value is IConvertible)
768  return (value as IConvertible).ToInt32(CultureInfo.InvariantCulture);
769 
770  throw new ArgumentException();
771  }
772 
773  public override void Clear() {
774  base.Clear();
775  InitToDefault();
776  }
777 
778  public override bool ContainsKey(string keyword) {
779  keyword = keyword.ToUpper().Trim();
780  if (!keymaps.ContainsKey(keyword))
781  return false;
782  return base.ContainsKey(keymaps[keyword]);
783  }
784 
785  public override bool Remove(string keyword) {
786  if (!ContainsKey(keyword))
787  return false;
788 
789  this[keyword] = null;
790  return true;
791  }
792 
793  public override bool ShouldSerialize(string keyword) {
794  if (!ContainsKey(keyword))
795  return false;
796 
797  keyword = keyword.ToUpper().Trim();
798  string key = keymaps[keyword];
799  if (persistSecurityInfo && key == PasswordKey)
800  return false;
801 
802  return base.ShouldSerialize(key);
803  }
804 
805  public override bool TryGetValue(string keyword, out object value) {
806  if (!ContainsKey(keyword)) {
807  value = null;
808  return false;
809  }
810 
811  return base.TryGetValue(keymaps[keyword.ToUpper().Trim()], out value);
812  }
813  }
814 }
The default implementation of a database in a system.
Definition: Database.cs:38
static readonly Dictionary< string, object > defaults
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
A SCHEMA object, that is a named container of multiple types of objects (eg. TABLE, PROCEDURE, VIEW, etc.).
override bool TryGetValue(string keyword, out object value)
static readonly Dictionary< string, string > keymaps