/******************************************************** * 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; #if !PLATFORM_COMPACTFRAMEWORK /// /// SQLite implementation of DbConnectionStringBuilder. /// public sealed class SQLiteConnectionStringBuilder : DbConnectionStringBuilder { /// /// 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) { ConnectionString = cnnString; Reset(); } /// /// Resets the builder to the default settings /// internal void Reset() { if (this.ContainsKey("Version") == false) Version = 3; if (ContainsKey("UseUTF16Encoding") == false) UseUTF16Encoding = false; if (ContainsKey("Cache Size") == false) CacheSize = 2000; if (ContainsKey("Synchronous") == false) SyncMode = SyncMode.Normal; if (ContainsKey("DateTimeFormat") == false) DateTimeFormat = DateTimeFormat.ISO8601; if (ContainsKey("Page Size") == false) PageSize = 4096; } /// /// 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. /// public int Version { get { return Convert.ToInt32(this["Version"]); } set { if (value != 3) throw new NotSupportedException(); this["Version"] = value; } } /// /// Gets/Sets the synchronous mode of the connection string. Default is "Normal". /// public SyncMode SyncMode { get { string s = this["Synchronous"].ToString().ToUpper(); switch (s) { case "FULL": return SyncMode.Full; case "OFF": return SyncMode.Off; default: return SyncMode.Normal; } } set { string s = "Normal"; if (value == SyncMode.Full) s = "Full"; else if (value == SyncMode.Off) s = "Off"; this["Synchronous"] = s; } } /// /// Gets/Sets the encoding for the connection string. The default is "False" which indicates UTF-8 encoding. /// public bool UseUTF16Encoding { get { return (this["UseUTF16Encoding"].ToString().ToUpper() == "TRUE"); } set { this["UseUTF16Encoding"] = ((value == true) ? "True" : "False"); } } /// /// Gets/Sets the filename to open on the connection string. /// public string DataSource { get { return this["Data Source"].ToString(); } set { this["Data Source"] = value; } } /// /// Gets/Sets the page size for the connection. /// public int PageSize { get { return Convert.ToInt32(this["Page Size"]); } set { this["Page Size"] = value; } } /// /// Gets/Sets the cache size for the connection. /// public int CacheSize { get { return Convert.ToInt32(this["Cache Size"]); } set { this["Cache Size"] = value; } } /// /// Gets/Sets the datetime format for the connection. /// public DateTimeFormat DateTimeFormat { get { switch(this["DateTimeFormat"].ToString().ToUpper()) { case "TICKS": return DateTimeFormat.Ticks; default: return DateTimeFormat.ISO8601; } } set { switch (value) { case DateTimeFormat.Ticks: this["DateTimeFormat"] = "Ticks"; break; case DateTimeFormat.ISO8601: this["DateTimeFormat"] = "ISO8601"; break; } } } } #endif }