[9dba08]: System.Data.SQLite / SQLiteConnectionStringBuilder.cs Maximize Restore History

Download this file

SQLiteConnectionStringBuilder.cs    479 lines (445 with data), 16.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Robert Simpson (robert@blackcastlesoft.com)
*
* Released to the public domain, use at your own risk!
********************************************************/
using System.Collections;
using System.ComponentModel;
using System.Data.Common;
using System.Globalization;
using System.Reflection;
namespace System.Data.SQLite
{
#if !PLATFORM_COMPACTFRAMEWORK
/// <summary>
/// SQLite implementation of DbConnectionStringBuilder.
/// </summary>
[DefaultProperty("DataSource")]
[DefaultMember("Item")]
public sealed class SQLiteConnectionStringBuilder : DbConnectionStringBuilder
{
/// <summary>
/// Properties of this class
/// </summary>
private Hashtable _properties;
/// <overloads>
/// Constructs a new instance of the class
/// </overloads>
/// <summary>
/// Default constructor
/// </summary>
public SQLiteConnectionStringBuilder()
{
Initialize(null);
}
/// <summary>
/// Constructs a new instance of the class using the specified connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse</param>
public SQLiteConnectionStringBuilder(string connectionString)
{
Initialize(connectionString);
}
/// <summary>
/// Gets/Sets the default version of the SQLite engine to instantiate. Currently the only valid value is 3, indicating version 3 of the sqlite library.
/// </summary>
[Browsable(true)]
[DefaultValue(3)]
public int Version
{
get
{
object value;
TryGetValue("version", out value);
return Convert.ToInt32(value, CultureInfo.CurrentCulture);
}
set
{
if (value != 3)
throw new NotSupportedException();
this["version"] = value;
}
}
/// <summary>
/// Gets/Sets the synchronization mode (file flushing) of the connection string. Default is "Normal".
/// </summary>
[DisplayName("Synchronous")]
[Browsable(true)]
[DefaultValue(SynchronizationModes.Normal)]
public SynchronizationModes SyncMode
{
get
{
object value;
TryGetValue("synchronous", out value);
if (value is string)
return
(SynchronizationModes)
TypeDescriptor.GetConverter(typeof (SynchronizationModes)).ConvertFrom(value);
else return (SynchronizationModes) value;
}
set { this["synchronous"] = value; }
}
/// <summary>
/// Gets/Sets the encoding for the connection string. The default is "False" which indicates UTF-8 encoding.
/// </summary>
[Browsable(true)]
[DefaultValue(false)]
public bool UseUTF16Encoding
{
get
{
object value;
TryGetValue("useutf16encoding", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["useutf16encoding"] = value; }
}
/// <summary>
/// Gets/Sets whether or not to use connection pooling. The default is "False"
/// </summary>
[Browsable(true)]
[DefaultValue(false)]
public bool Pooling
{
get
{
object value;
TryGetValue("pooling", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["pooling"] = value; }
}
/// <summary>
/// Gets/Sets whethor not to store GUID's in binary format. The default is True
/// which saves space in the database.
/// </summary>
[Browsable(true)]
[DefaultValue(true)]
public bool BinaryGUID
{
get
{
object value;
TryGetValue("binaryguid", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["binaryguid"] = value; }
}
/// <summary>
/// Gets/Sets the filename to open on the connection string.
/// </summary>
[DisplayName("Data Source")]
[Browsable(true)]
[DefaultValue("")]
public string DataSource
{
get
{
object value;
TryGetValue("data source", out value);
return value.ToString();
}
set { this["data source"] = value; }
}
/// <summary>
/// An alternate to the data source property
/// </summary>
[Browsable(false)]
public string Uri
{
get
{
object value;
TryGetValue("uri", out value);
return value.ToString();
}
set { this["uri"] = value; }
}
/// <summary>
/// Gets/sets the default command timeout for newly-created commands. This is especially useful for
/// commands used internally such as inside a SQLiteTransaction, where setting the timeout is not possible.
/// </summary>
[DisplayName("Default Timeout")]
[Browsable(true)]
[DefaultValue(30)]
public int DefaultTimeout
{
get
{
object value;
TryGetValue("default timeout", out value);
return Convert.ToInt32(value, CultureInfo.CurrentCulture);
}
set { this["default timeout"] = value; }
}
/// <summary>
/// Determines whether or not the connection will automatically participate
/// in the current distributed transaction (if one exists)
/// </summary>
[Browsable(true)]
[DefaultValue(true)]
public bool Enlist
{
get
{
object value;
TryGetValue("enlist", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["enlist"] = value; }
}
/// <summary>
/// If set to true, will throw an exception if the database specified in the connection
/// string does not exist. If false, the database will be created automatically.
/// </summary>
[Browsable(true)]
[DefaultValue(false)]
public bool FailIfMissing
{
get
{
object value;
TryGetValue("failifmissing", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["failifmissing"] = value; }
}
/// <summary>
/// If enabled, uses the legacy 3.xx format for maximum compatibility, but results in larger
/// database sizes.
/// </summary>
[DisplayName("Legacy Format")]
[Browsable(true)]
[DefaultValue(false)]
public bool LegacyFormat
{
get
{
object value;
TryGetValue("legacy format", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["legacy format"] = value; }
}
/// <summary>
/// When enabled, the database will be opened for read-only access and writing will be disabled.
/// </summary>
[DisplayName("Read Only")]
[Browsable(true)]
[DefaultValue(false)]
public bool ReadOnly
{
get
{
object value;
TryGetValue("read only", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["read only"] = value; }
}
/// <summary>
/// Gets/sets the database encryption password
/// </summary>
[Browsable(true)]
[PasswordPropertyText(true)]
[DefaultValue("")]
public string Password
{
get
{
object value;
TryGetValue("password", out value);
return value.ToString();
}
set { this["password"] = value; }
}
/// <summary>
/// Gets/Sets the page size for the connection.
/// </summary>
[DisplayName("Page Size")]
[Browsable(true)]
[DefaultValue(1024)]
public int PageSize
{
get
{
object value;
TryGetValue("page size", out value);
return Convert.ToInt32(value, CultureInfo.CurrentCulture);
}
set { this["page size"] = value; }
}
/// <summary>
/// Gets/Sets the maximum number of pages the database may hold
/// </summary>
[DisplayName("Max Page Count")]
[Browsable(true)]
[DefaultValue(0)]
public int MaxPageCount
{
get
{
object value;
TryGetValue("max page count", out value);
return Convert.ToInt32(value, CultureInfo.CurrentCulture);
}
set { this["max page count"] = value; }
}
/// <summary>
/// Gets/Sets the cache size for the connection.
/// </summary>
[DisplayName("Cache Size")]
[Browsable(true)]
[DefaultValue(2000)]
public int CacheSize
{
get
{
object value;
TryGetValue("cache size", out value);
return Convert.ToInt32(value, CultureInfo.CurrentCulture);
}
set { this["cache size"] = value; }
}
/// <summary>
/// Gets/Sets the datetime format for the connection.
/// </summary>
[Browsable(true)]
[DefaultValue(SQLiteDateFormats.ISO8601)]
public SQLiteDateFormats DateTimeFormat
{
get
{
object value;
TryGetValue("datetimeformat", out value);
if (value is string)
return
(SQLiteDateFormats) TypeDescriptor.GetConverter(typeof (SQLiteDateFormats)).ConvertFrom(value);
else return (SQLiteDateFormats) value;
}
set { this["datetimeformat"] = value; }
}
/// <summary>
/// Determines how SQLite handles the transaction journal file.
/// </summary>
[Browsable(true)]
[DefaultValue(SQLiteJournalModeEnum.Delete)]
[DisplayName("Journal Mode")]
public SQLiteJournalModeEnum JournalMode
{
get
{
object value;
TryGetValue("journal mode", out value);
if (value is string)
return
(SQLiteJournalModeEnum)
TypeDescriptor.GetConverter(typeof (SQLiteJournalModeEnum)).ConvertFrom(value);
else
return (SQLiteJournalModeEnum) value;
}
set { this["journal mode"] = value; }
}
/// <summary>
/// Sets the default isolation level for transactions on the connection.
/// </summary>
[Browsable(true)]
[DefaultValue(IsolationLevel.Serializable)]
[DisplayName("Default Isolation Level")]
public IsolationLevel DefaultIsolationLevel
{
get
{
object value;
TryGetValue("default isolationlevel", out value);
if (value is string)
return (IsolationLevel) TypeDescriptor.GetConverter(typeof (IsolationLevel)).ConvertFrom(value);
else
return (IsolationLevel) value;
}
set { this["default isolationlevel"] = value; }
}
/// <summary>
/// If enabled, use foreign key constraints
/// </summary>
[DisplayName("Foreign Keys")]
[Browsable(true)]
[DefaultValue(false)]
public bool ForeignKeys
{
get
{
object value;
TryGetValue("foreign keys", out value);
return SQLiteConvert.ToBoolean(value);
}
set { this["foreign keys"] = value; }
}
/// <summary>
/// Private initializer, which assigns the connection string and resets the builder
/// </summary>
/// <param name="cnnString">The connection string to assign</param>
private void Initialize(string cnnString)
{
_properties = new Hashtable(StringComparer.OrdinalIgnoreCase);
try
{
base.GetProperties(_properties);
}
catch (NotImplementedException)
{
FallbackGetProperties(_properties);
}
if (String.IsNullOrEmpty(cnnString) == false)
ConnectionString = cnnString;
}
/// <summary>
/// Helper function for retrieving values from the connectionstring
/// </summary>
/// <param name="keyword">The keyword to retrieve settings for</param>
/// <param name="value">The resulting parameter value</param>
/// <returns>Returns true if the value was found and returned</returns>
public override bool TryGetValue(string keyword, out object value)
{
bool b = base.TryGetValue(keyword, out value);
if (!_properties.ContainsKey(keyword)) return b;
var pd = _properties[keyword] as PropertyDescriptor;
if (pd == null) return b;
// Attempt to coerce the value into something more solid
if (b)
{
if (pd.PropertyType == typeof (Boolean))
value = SQLiteConvert.ToBoolean(value);
else
value = TypeDescriptor.GetConverter(pd.PropertyType).ConvertFrom(value);
}
else
{
var att = pd.Attributes[typeof (DefaultValueAttribute)] as DefaultValueAttribute;
if (att != null)
{
value = att.Value;
b = true;
}
}
return b;
}
/// <summary>
/// Fallback method for MONO, which doesn't implement DbConnectionStringBuilder.GetProperties()
/// </summary>
/// <param name="propertyList">The hashtable to fill with property descriptors</param>
private void FallbackGetProperties(Hashtable propertyList)
{
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(this, true))
{
if (descriptor.Name != "ConnectionString" && propertyList.ContainsKey(descriptor.DisplayName) == false)
{
propertyList.Add(descriptor.DisplayName, descriptor);
}
}
}
}
#endif
}