19 using System.Collections.Generic;
20 using System.ComponentModel;
22 using System.Globalization;
26 namespace Deveel.Data.Client {
27 [DefaultProperty(
"DataSource")]
31 ConnectionString = connectionString;
35 : this(String.Empty) {
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);
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;
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";
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;
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;
185 private static readonly Dictionary<string, object>
defaults;
186 private static readonly Dictionary<string, string>
keymaps;
209 public override bool IsFixedSize {
213 public override object this[
string keyword] {
215 keyword = MappKey(keyword);
216 if (base.ContainsKey(keyword))
217 return base[keyword];
218 return defaults[keyword];
220 set { SetValue(keyword, value); }
223 public override ICollection Keys {
225 var keys =
new List<string> {
233 PersistSecurityInfoKey,
234 VerboseColumnNamesKey,
239 IgnoreIdentifiersCaseKey,
247 return keys.AsReadOnly();
251 public override ICollection Values {
253 var list =
new List<object> {
275 return list.AsReadOnly();
279 [DisplayName(
"Data Source")]
280 [RefreshProperties(RefreshProperties.All)]
281 public string DataSource {
283 string dataSource = Host;
284 if (Port > 0 && Port != DefaultPort)
285 dataSource +=
":" + Port;
291 throw new ArgumentNullException(
"value");
293 base[
"Data Source"] = value;
295 int index = value.IndexOf(
':');
297 Port = Int32.Parse(value.Substring(index));
298 value = value.Substring(0, index);
305 [DisplayName(
"Host Address")]
306 [RefreshProperties(RefreshProperties.All)]
311 base[HostKey] = value;
315 [DisplayName(
"Server Port")]
316 [RefreshProperties(RefreshProperties.All)]
321 base[PortKey] = value;
325 [DisplayName(
"Database Name")]
326 [RefreshProperties(RefreshProperties.All)]
328 get {
return database; }
330 base[DatabaseKey] = value;
335 [DisplayName(
"Schema")]
336 [RefreshProperties(RefreshProperties.All)]
338 get {
return schema; }
340 base[SchemaKey] = value;
345 [DisplayName(
"User Name")]
346 [RefreshProperties(RefreshProperties.All)]
347 public string UserName {
348 get {
return userName; }
350 base[UserNameKey] = value;
355 [DisplayName(
"User Password")]
356 [PasswordPropertyText(
true)]
357 [RefreshProperties(RefreshProperties.All)]
358 public string Password {
359 get {
return password; }
361 base[PasswordKey] = value;
366 [DisplayName(
"Persist Security Info")]
367 [RefreshProperties(RefreshProperties.All)]
368 public bool PersistSecurityInfo {
369 get {
return persistSecurityInfo; }
371 base[PersistSecurityInfoKey] = value;
372 persistSecurityInfo = value;
376 [DisplayName(
"Verbose Column Names")]
377 [RefreshProperties(RefreshProperties.All)]
378 public bool VerboseColumnNames {
379 get {
return verboseColumnNames; }
381 base[VerboseColumnNamesKey] = value;
382 verboseColumnNames = value;
386 [DisplayName(
"Parameter Style")]
387 [RefreshProperties(RefreshProperties.All)]
389 get {
return paramStyle; }
391 base[ParameterStyleKey] = value;
396 [DisplayName(
"Data Path")]
397 [RefreshProperties(RefreshProperties.All)]
401 base[PathKey] = value;
406 [DisplayName(
"Row Cache Size")]
407 [RefreshProperties(RefreshProperties.All)]
408 public int RowCacheSize {
409 get {
return rowCacheSize; }
411 base[RowCacheSizeKey] = value;
412 rowCacheSize = value;
416 [DisplayName(
"Max Cache Size")]
417 [RefreshProperties(RefreshProperties.All)]
418 public int MaxCacheSize {
419 get {
return maxCacheSize; }
421 base[MaxCacheSizeKey] = value;
422 maxCacheSize = value;
426 [DisplayName(
"Query Timeout")]
427 [RefreshProperties(RefreshProperties.All)]
428 public int QueryTimeout {
429 get {
return queryTimeout; }
431 base[QueryTimeoutKey] = value;
432 queryTimeout = value;
436 [DisplayName(
"Ignore Identifiers Case")]
437 [RefreshProperties(RefreshProperties.All)]
438 public bool IgnoreIdentifiersCase {
439 get {
return ignoreCase; }
441 base[IgnoreIdentifiersCaseKey] = value;
446 [DisplayName(
"Create New Database")]
447 [RefreshProperties(RefreshProperties.All)]
449 get {
return create; }
451 base[CreateKey] = value;
456 [DisplayName(
"Boot/Create Database")]
457 [RefreshProperties(RefreshProperties.All)]
458 public bool BootOrCreate {
459 get {
return bootOrCreate; }
461 base[BootOrCreateKey] = value;
462 bootOrCreate = value;
466 [DisplayName(
"Strict GetValue")]
467 [RefreshProperties(RefreshProperties.All)]
468 public bool StrictGetValue {
469 get {
return strictGetValue; }
471 base[StrictGetValueKey] = value;
472 strictGetValue = value;
476 [DisplayName(
"Fetch Size")]
477 [RefreshProperties(RefreshProperties.All)]
478 public int FetchSize {
479 get {
return fetchSize; }
481 base[FetchSizeKey] = value;
486 [DisplayName(
"Max Fetch Size")]
487 [RefreshProperties(RefreshProperties.All)]
488 public int MaxFetchSize {
489 get {
return maxFetchSize; }
491 base[MaxFetchSizeKey] = value;
492 maxFetchSize = value;
496 [DisplayName(
"Auto-Commit")]
497 [RefreshProperties(RefreshProperties.All)]
498 public bool AutoCommit {
499 get {
return autoCommit; }
501 base[AutoCommitKey] = value;
509 database = DefaultDatabase;
510 userName = DefaultUserName;
511 password = DefaultPassword;
512 schema = DefaultSchema;
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;
531 throw new ArgumentNullException(
"key");
541 Host = value.ToString();
550 Port = ToInt32(value);
555 database = DefaultDatabase;
563 schema = DefaultSchema;
566 Schema = value.ToString();
574 Path = value.ToString();
579 userName = DefaultUserName;
582 UserName = value.ToString();
587 password = DefaultPassword;
590 Password = value.ToString();
593 case PersistSecurityInfoKey:
595 persistSecurityInfo = DefaultPersistSecurityInfo;
598 PersistSecurityInfo = ToBoolean(value);
601 case VerboseColumnNamesKey:
603 verboseColumnNames = DefaultVerboseColumnName;
606 VerboseColumnNames = ToBoolean(value);
609 case ParameterStyleKey:
611 paramStyle = DefaultParameterStyle;
613 }
else if (value is
string) {
615 }
else if (value is
int ||
620 case RowCacheSizeKey:
622 rowCacheSize = DefaultRowCacheSize;
625 RowCacheSize = ToInt32(value);
628 case MaxCacheSizeKey:
630 maxCacheSize = DefaultMaxCacheSize;
633 MaxCacheSize = ToInt32(value);
636 case QueryTimeoutKey:
638 queryTimeout = DefaultQueryTimeout;
641 QueryTimeout = ToInt32(value);
644 case IgnoreIdentifiersCaseKey:
646 ignoreCase = DefaultIgnoreIdentifiersCase;
649 IgnoreIdentifiersCase = ToBoolean(value);
654 create = DefaultCreate;
657 Create = ToBoolean(value);
660 case BootOrCreateKey:
662 bootOrCreate = DefaultBootOrCreate;
665 BootOrCreate = ToBoolean(value);
668 case StrictGetValueKey:
670 strictGetValue = DefaultStrictGetValue;
673 StrictGetValue = ToBoolean(value);
680 string s = value.ToString();
681 int index = s.IndexOf(
':');
683 string sPort = s.Substring(index + 1);
684 Host = s.Substring(0, index);
685 Port = Int32.Parse(sPort);
693 fetchSize = DefaultFetchSize;
694 base.Remove(FetchSizeKey);
696 FetchSize = ToInt32(value);
699 case MaxFetchSizeKey:
701 maxFetchSize = DefaultMaxFetchSize;
702 base.Remove(MaxFetchSizeKey);
704 MaxFetchSize = ToInt32(value);
709 autoCommit = DefaultAutoCommit;
710 base.Remove(AutoCommitKey);
712 AutoCommit = ToBoolean(value);
717 throw new ArgumentException(
"Key '" + key +
"' is not recognized.",
"key");
723 if (String.Equals(key,
"DataSource", StringComparison.InvariantCultureIgnoreCase))
727 if (!keymaps.TryGetValue(key, out outKey))
728 throw new ArgumentException(
"The connection string keyword is not supported: " + key);
734 throw new ArgumentException();
739 if (value is
string) {
740 string s = value.ToString().ToUpper();
741 if (s ==
"YES" || s ==
"ENABLED" ||
742 s ==
"TRUE" || s ==
"ON")
744 if (s ==
"NO" || s ==
"DISABLED" ||
745 s ==
"FALSE" || s ==
"OFF")
749 if (value is IConvertible)
750 return (value as IConvertible).ToBoolean(CultureInfo.InvariantCulture);
752 throw new ArgumentException();
757 throw new ArgumentException();
762 if (value is
string) {
763 string s = value.ToString();
764 return Int32.Parse(s, CultureInfo.InvariantCulture);
767 if (value is IConvertible)
768 return (value as IConvertible).ToInt32(CultureInfo.InvariantCulture);
770 throw new ArgumentException();
779 keyword = keyword.ToUpper().Trim();
780 if (!keymaps.ContainsKey(keyword))
782 return base.ContainsKey(keymaps[keyword]);
785 public override bool Remove(
string keyword) {
786 if (!ContainsKey(keyword))
789 this[keyword] = null;
794 if (!ContainsKey(keyword))
797 keyword = keyword.ToUpper().Trim();
798 string key = keymaps[keyword];
799 if (persistSecurityInfo && key == PasswordKey)
802 return base.ShouldSerialize(key);
805 public override bool TryGetValue(
string keyword, out
object value) {
806 if (!ContainsKey(keyword)) {
811 return base.TryGetValue(keymaps[keyword.ToUpper().Trim()], out value);
DeveelDbConnectionStringBuilder()
static DeveelDbConnectionStringBuilder()
void SetValue(string key, object value)
override bool ContainsKey(string keyword)
The default implementation of a database in a system.
static bool ToBoolean(object value)
static int ToInt32(object value)
static readonly Dictionary< string, object > defaults
override bool ShouldSerialize(string keyword)
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)
QueryParameterStyle paramStyle
DeveelDbConnectionStringBuilder(string connectionString)
override bool Remove(string keyword)
static readonly Dictionary< string, string > keymaps
string MappKey(string key)