/********************************************************
* 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!
********************************************************/
namespace System.Data.SQLite
{
using System;
using System.Data.Common;
using System.ComponentModel;
using System.Collections;
using System.Globalization;
using System.Reflection;
#if !PLATFORM_COMPACTFRAMEWORK
using System.ComponentModel.Design;
///
/// SQLite implementation of DbConnectionStringBuilder.
///
[DefaultProperty("DataSource")]
[DefaultMember("Item")]
public sealed class SQLiteConnectionStringBuilder : DbConnectionStringBuilder
{
///
/// Properties of this class
///
private Hashtable _properties;
///
/// Constructs a new instance of the class
///
///
/// Default constructor
///
public SQLiteConnectionStringBuilder()
{
Initialize(null);
}
///
/// Constructs a new instance of the class using the specified connection string.
///
/// The connection string to parse
public SQLiteConnectionStringBuilder(string connectionString)
{
Initialize(connectionString);
}
///
/// Private initializer, which assigns the connection string and resets the builder
///
/// The connection string to assign
private void Initialize(string cnnString)
{
_properties = new Hashtable();
base.GetProperties(_properties);
if (String.IsNullOrEmpty(cnnString) == false)
ConnectionString = cnnString;
}
///
/// 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.
///
[Browsable(true)]
[DefaultValue(3)]
public int Version
{
get
{
if (ContainsKey("Version") == false) return 3;
return Convert.ToInt32(this["Version"], CultureInfo.CurrentCulture);
}
set
{
if (value != 3)
throw new NotSupportedException();
this["Version"] = value;
}
}
///
/// Gets/Sets the synchronous mode of the connection string. Default is "Normal".
///
[DisplayName("Synchronous")]
[Browsable(true)]
[DefaultValue(SynchronizationModes.Normal)]
public SynchronizationModes SyncMode
{
get
{
return (SynchronizationModes)TypeDescriptor.GetConverter(typeof(SynchronizationModes)).ConvertFrom(this["Synchronous"]);
}
set
{
this["Synchronous"] = value;
}
}
///
/// Gets/Sets the encoding for the connection string. The default is "False" which indicates UTF-8 encoding.
///
[Browsable(true)]
[DefaultValue(false)]
public bool UseUTF16Encoding
{
get
{
return Convert.ToBoolean(this["UseUTF16Encoding"], CultureInfo.CurrentCulture);
}
set
{
this["UseUTF16Encoding"] = value;
}
}
///
/// Gets/Sets the filename to open on the connection string.
///
[DisplayName("Data Source")]
[Browsable(true)]
public string DataSource
{
get
{
if (ContainsKey("Data Source") == false) return "";
return this["Data Source"].ToString();
}
set
{
this["Data Source"] = value;
}
}
///
/// Gets/Sets the page size for the connection.
///
[DisplayName("Page Size")]
[Browsable(true)]
[DefaultValue(1024)]
public int PageSize
{
get
{
if (ContainsKey("Page Size") == false) return 1024;
return Convert.ToInt32(this["Page Size"], CultureInfo.InvariantCulture);
}
set
{
this["Page Size"] = value;
}
}
///
/// Gets/Sets the cache size for the connection.
///
[DisplayName("Cache Size")]
[Browsable(true)]
[DefaultValue(2000)]
public int CacheSize
{
get
{
if (ContainsKey("Cache Size") == false) return 2000;
return Convert.ToInt32(this["Cache Size"], CultureInfo.InvariantCulture);
}
set
{
this["Cache Size"] = value;
}
}
///
/// Gets/Sets the datetime format for the connection.
///
[Browsable(true)]
[DefaultValue(SQLiteDateFormats.ISO8601)]
public SQLiteDateFormats DateTimeFormat
{
get
{
if (ContainsKey("DateTimeFormat") == false) return SQLiteDateFormats.ISO8601;
return (SQLiteDateFormats)TypeDescriptor.GetConverter(typeof(SQLiteDateFormats)).ConvertFrom(this["DateTimeFormat"]);
}
set
{
this["DateTimeFormat"] = value;
}
}
///
/// Helper function for retrieving values from the connectionstring
///
/// The keyword to retrieve settings for
/// The resulting parameter value
/// Returns true if the value was found and returned
public override bool TryGetValue(string keyword, out object value)
{
bool b = base.TryGetValue(keyword, out value);
if (!_properties.ContainsKey(keyword)) return b;
PropertyDescriptor pd = _properties[keyword] as PropertyDescriptor;
if (pd == null) return b;
if (b)
{
value = TypeDescriptor.GetConverter(pd.PropertyType).ConvertFrom(value);
}
else
{
DefaultValueAttribute att = pd.Attributes[typeof(DefaultValueAttribute)] as DefaultValueAttribute;
if (att != null)
{
value = att.Value;
b = true;
}
}
return b;
}
}
#endif
}