Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / Mono.Data.Sqlite / Mono.Data.Sqlite_2.0 / SQLiteConnection.cs
index dbe0401f39d646dafedae46b94b963c033b8c873..961184bb0d7febfc94023cb7fd00418941927d9f 100644 (file)
@@ -21,7 +21,7 @@ namespace Mono.Data.Sqlite
   /// SQLite implentation of DbConnection.\r
   /// </summary>\r
   /// <remarks>\r
-  /// The <see cref="ConnectionString">ConnectionString</see> property of the SQLiteConnection class can contain the following parameter(s), delimited with a semi-colon:\r
+  /// The <see cref="ConnectionString">ConnectionString</see> property of the SqliteConnection class can contain the following parameter(s), delimited with a semi-colon:\r
   /// <list type="table">\r
   /// <listheader>\r
   /// <term>Parameter</term>\r
@@ -145,7 +145,7 @@ namespace Mono.Data.Sqlite
   /// </item>\r
   /// </list>\r
   /// </remarks>\r
-  public sealed partial class SQLiteConnection : DbConnection, ICloneable\r
+  public sealed partial class SqliteConnection : DbConnection, ICloneable\r
   {\r
     private const string _dataDirectory = "|DataDirectory|";\r
     private const string _masterdb = "sqlite_master";\r
@@ -211,12 +211,12 @@ namespace Mono.Data.Sqlite
     public override event StateChangeEventHandler StateChange;\r
 \r
     ///<overloads>\r
-    /// Constructs a new SQLiteConnection object\r
+    /// Constructs a new SqliteConnection object\r
     /// </overloads>\r
     /// <summary>\r
     /// Default constructor\r
     /// </summary>\r
-    public SQLiteConnection()\r
+    public SqliteConnection()\r
       : this("")\r
     {\r
     }\r
@@ -225,7 +225,7 @@ namespace Mono.Data.Sqlite
     /// Initializes the connection with the specified connection string\r
     /// </summary>\r
     /// <param name="connectionString">The connection string to use on the connection</param>\r
-    public SQLiteConnection(string connectionString)\r
+    public SqliteConnection(string connectionString)\r
     {\r
       _sql = null;\r
       _connectionState = ConnectionState.Closed;\r
@@ -244,7 +244,7 @@ namespace Mono.Data.Sqlite
     /// attach to them.\r
     /// </summary>\r
     /// <param name="connection"></param>\r
-    public SQLiteConnection(SQLiteConnection connection)\r
+    public SqliteConnection(SqliteConnection connection)\r
       : this(connection.ConnectionString)\r
     {\r
       string str;\r
@@ -262,7 +262,7 @@ namespace Mono.Data.Sqlite
             if (String.Compare(str, "main", true, CultureInfo.InvariantCulture) != 0\r
               && String.Compare(str, "temp", true, CultureInfo.InvariantCulture) != 0)\r
             {\r
-              using (SQLiteCommand cmd = CreateCommand())\r
+              using (SqliteCommand cmd = CreateCommand())\r
               {\r
                 cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "ATTACH DATABASE '{0}' AS [{1}]", row[1], row[0]);\r
                 cmd.ExecuteNonQuery();\r
@@ -293,17 +293,20 @@ namespace Mono.Data.Sqlite
     /// <returns></returns>\r
     public object Clone()\r
     {\r
-      return new SQLiteConnection(this);\r
+      return new SqliteConnection(this);\r
     }\r
 \r
     /// <summary>\r
-    /// Disposes of the SQLiteConnection, closing it if it is active.\r
+    /// Disposes of the SqliteConnection, closing it if it is active.\r
     /// </summary>\r
     /// <param name="disposing">True if the connection is being explicitly closed.</param>\r
     protected override void Dispose(bool disposing)\r
     {\r
       base.Dispose(disposing);\r
 \r
+      if (_sql != null)\r
+        _sql.Dispose ();\r
+\r
       if (disposing)\r
         Close();\r
     }\r
@@ -362,34 +365,34 @@ namespace Mono.Data.Sqlite
     }\r
 \r
     /// <summary>\r
-    /// OBSOLETE.  Creates a new SQLiteTransaction if one isn't already active on the connection.\r
+    /// OBSOLETE.  Creates a new SqliteTransaction if one isn't already active on the connection.\r
     /// </summary>\r
     /// <param name="isolationLevel">This parameter is ignored.</param>\r
     /// <param name="deferredLock">When TRUE, SQLite defers obtaining a write lock until a write operation is requested.\r
     /// When FALSE, a writelock is obtained immediately.  The default is TRUE, but in a multi-threaded multi-writer \r
     /// environment, one may instead choose to lock the database immediately to avoid any possible writer deadlock.</param>\r
-    /// <returns>Returns a SQLiteTransaction object.</returns>\r
+    /// <returns>Returns a SqliteTransaction object.</returns>\r
     [Obsolete("Use one of the standard BeginTransaction methods, this one will be removed soon")]\r
-    public SQLiteTransaction BeginTransaction(IsolationLevel isolationLevel, bool deferredLock)\r
+    public SqliteTransaction BeginTransaction(IsolationLevel isolationLevel, bool deferredLock)\r
     {\r
-      return (SQLiteTransaction)BeginDbTransaction(deferredLock == false ? IsolationLevel.Serializable : IsolationLevel.ReadCommitted);\r
+      return (SqliteTransaction)BeginDbTransaction(deferredLock == false ? IsolationLevel.Serializable : IsolationLevel.ReadCommitted);\r
     }\r
 \r
     /// <summary>\r
-    /// OBSOLETE.  Creates a new SQLiteTransaction if one isn't already active on the connection.\r
+    /// OBSOLETE.  Creates a new SqliteTransaction if one isn't already active on the connection.\r
     /// </summary>\r
     /// <param name="deferredLock">When TRUE, SQLite defers obtaining a write lock until a write operation is requested.\r
     /// When FALSE, a writelock is obtained immediately.  The default is false, but in a multi-threaded multi-writer \r
     /// environment, one may instead choose to lock the database immediately to avoid any possible writer deadlock.</param>\r
-    /// <returns>Returns a SQLiteTransaction object.</returns>\r
+    /// <returns>Returns a SqliteTransaction object.</returns>\r
     [Obsolete("Use one of the standard BeginTransaction methods, this one will be removed soon")]\r
-    public SQLiteTransaction BeginTransaction(bool deferredLock)\r
+    public SqliteTransaction BeginTransaction(bool deferredLock)\r
     {\r
-      return (SQLiteTransaction)BeginDbTransaction(deferredLock == false ? IsolationLevel.Serializable : IsolationLevel.ReadCommitted);\r
+      return (SqliteTransaction)BeginDbTransaction(deferredLock == false ? IsolationLevel.Serializable : IsolationLevel.ReadCommitted);\r
     }\r
 \r
     /// <summary>\r
-    /// Creates a new SQLiteTransaction if one isn't already active on the connection.\r
+    /// Creates a new SqliteTransaction if one isn't already active on the connection.\r
     /// </summary>\r
     /// <param name="isolationLevel">Supported isolation levels are Serializable, ReadCommitted and Unspecified.</param>\r
     /// <remarks>\r
@@ -401,19 +404,19 @@ namespace Mono.Data.Sqlite
     /// a transaction in ReadCommitted mode, but if a thread attempts to commit a transaction while another thread\r
     /// has a ReadCommitted lock, it may timeout or cause a deadlock on both threads until both threads' CommandTimeout's are reached.\r
     /// </remarks>\r
-    /// <returns>Returns a SQLiteTransaction object.</returns>\r
-    public new SQLiteTransaction BeginTransaction(IsolationLevel isolationLevel)\r
+    /// <returns>Returns a SqliteTransaction object.</returns>\r
+    public new SqliteTransaction BeginTransaction(IsolationLevel isolationLevel)\r
     {\r
-      return (SQLiteTransaction)BeginDbTransaction(isolationLevel);\r
+      return (SqliteTransaction)BeginDbTransaction(isolationLevel);\r
     }\r
 \r
     /// <summary>\r
-    /// Creates a new SQLiteTransaction if one isn't already active on the connection.\r
+    /// Creates a new SqliteTransaction if one isn't already active on the connection.\r
     /// </summary>\r
-    /// <returns>Returns a SQLiteTransaction object.</returns>\r
-    public new SQLiteTransaction BeginTransaction()\r
+    /// <returns>Returns a SqliteTransaction object.</returns>\r
+    public new SqliteTransaction BeginTransaction()\r
     {\r
-      return (SQLiteTransaction)BeginDbTransaction(_defaultIsolation);\r
+      return (SqliteTransaction)BeginDbTransaction(_defaultIsolation);\r
     }\r
 \r
     /// <summary>\r
@@ -431,7 +434,7 @@ namespace Mono.Data.Sqlite
       if (isolationLevel != IsolationLevel.Serializable && isolationLevel != IsolationLevel.ReadCommitted)\r
         throw new ArgumentException("isolationLevel");\r
 \r
-      return new SQLiteTransaction(this, isolationLevel != IsolationLevel.Serializable);\r
+      return new SqliteTransaction(this, isolationLevel != IsolationLevel.Serializable);\r
     }\r
 \r
     /// <summary>\r
@@ -456,7 +459,7 @@ namespace Mono.Data.Sqlite
           // If the connection is enlisted in a transaction scope and the scope is still active,\r
           // we cannot truly shut down this connection until the scope has completed.  Therefore make a \r
           // hidden connection temporarily to hold open the connection until the scope has completed.\r
-          SQLiteConnection cnn = new SQLiteConnection();\r
+          SqliteConnection cnn = new SqliteConnection();\r
           cnn._sql = _sql;\r
           cnn._transactionLevel = _transactionLevel;\r
           cnn._enlistment = _enlistment;\r
@@ -484,7 +487,7 @@ namespace Mono.Data.Sqlite
     /// will be discarded instead of returned to the pool when they are closed.\r
     /// </summary>\r
     /// <param name="connection"></param>\r
-    public static void ClearPool(SQLiteConnection connection)\r
+    public static void ClearPool(SqliteConnection connection)\r
     {\r
       if (connection._sql == null) return;\r
       connection._sql.ClearPool();\r
@@ -495,7 +498,7 @@ namespace Mono.Data.Sqlite
     /// </summary>\r
     public static void ClearAllPools()\r
     {\r
-      SQLiteConnectionPool.ClearAllPools();\r
+      SqliteConnectionPool.ClearAllPools();\r
     }\r
 \r
     /// <summary>\r
@@ -627,7 +630,7 @@ namespace Mono.Data.Sqlite
     /// </remarks>\r
 #if !PLATFORM_COMPACTFRAMEWORK\r
     [RefreshProperties(RefreshProperties.All), DefaultValue("")]\r
-    [Editor("SQLite.Designer.SQLiteConnectionStringEditor, SQLite.Designer, Version=1.0.36.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]\r
+    [Editor("SQLite.Designer.SqliteConnectionStringEditor, SQLite.Designer, Version=1.0.36.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]\r
 #endif\r
     public override string ConnectionString\r
     {\r
@@ -648,12 +651,12 @@ namespace Mono.Data.Sqlite
     }\r
 \r
     /// <summary>\r
-    /// Create a new SQLiteCommand and associate it with this connection.\r
+    /// Create a new SqliteCommand and associate it with this connection.\r
     /// </summary>\r
-    /// <returns>Returns an instantiated SQLiteCommand object already assigned to this connection.</returns>\r
-    public new SQLiteCommand CreateCommand()\r
+    /// <returns>Returns an instantiated SqliteCommand object already assigned to this connection.</returns>\r
+    public new SqliteCommand CreateCommand()\r
     {\r
-      return new SQLiteCommand(this);\r
+      return new SqliteCommand(this);\r
     }\r
 \r
     /// <summary>\r
@@ -693,6 +696,42 @@ namespace Mono.Data.Sqlite
       }\r
     }\r
 \r
+    /// <summary>\r
+    /// Maps mono-specific connection string keywords to the standard ones\r
+    /// </summary>\r
+    /// <returns>The mapped keyword name</returns>\r
+    internal static void MapMonoKeyword (string[] arPiece, SortedList<string, string> ls)\r
+    {\r
+            string keyword, value;\r
+            \r
+            switch (arPiece[0].ToLower (CultureInfo.InvariantCulture)) {\r
+                    case "uri":\r
+                            keyword = "Data Source";\r
+                            value = MapMonoUriPath (arPiece[1]);\r
+                            break;\r
+                            \r
+                    default:\r
+                            keyword = arPiece[0];\r
+                            value = arPiece[1];\r
+                            break;\r
+            }\r
+\r
+            ls.Add(keyword, value);\r
+    }\r
+\r
+    internal static string MapMonoUriPath (string path)\r
+    {\r
+            if (path.StartsWith ("file://")) {\r
+                    return path.Substring (7);\r
+            } else if (path.StartsWith ("file:")) {\r
+                    return path.Substring (5);\r
+            } else if (path.StartsWith ("/")) {\r
+                    return path;\r
+            } else {\r
+                    throw new InvalidOperationException ("Invalid connection string: invalid URI");\r
+            }\r
+    }\r
+\r
     internal static string MapUriPath(string path)\r
     {\r
            if (path.StartsWith ("file://"))\r
@@ -712,23 +751,23 @@ namespace Mono.Data.Sqlite
     /// <returns>An array of key-value pairs representing each parameter of the connection string</returns>\r
     internal static SortedList<string, string> ParseConnectionString(string connectionString)\r
     {\r
-      string s = connectionString;\r
+      string s = connectionString.Replace (',', ';'); // Mono compatibility\r
       int n;\r
       SortedList<string, string> ls = new SortedList<string, string>(StringComparer.OrdinalIgnoreCase);\r
 \r
       // First split into semi-colon delimited values.  The Split() function of SQLiteBase accounts for and properly\r
       // skips semi-colons in quoted strings\r
-      string[] arParts = SQLiteConvert.Split(s, ';');\r
+      string[] arParts = SqliteConvert.Split(s, ';');\r
       string[] arPiece;\r
 \r
       int x = arParts.Length;\r
       // For each semi-colon piece, split into key and value pairs by the presence of the = sign\r
       for (n = 0; n < x; n++)\r
       {\r
-        arPiece = SQLiteConvert.Split(arParts[n], '=');\r
+        arPiece = SqliteConvert.Split(arParts[n], '=');\r
         if (arPiece.Length == 2)\r
         {\r
-          ls.Add(arPiece[0], arPiece[1]);\r
+         MapMonoKeyword (arPiece, ls);\r
         }\r
         else throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Invalid ConnectionString format for parameter \"{0}\"", (arPiece.Length > 0) ? arPiece[0] : "null"));\r
       }\r
@@ -807,8 +846,8 @@ namespace Mono.Data.Sqlite
       }\r
       try\r
       {\r
-        bool usePooling = (SQLiteConvert.ToBoolean(FindKey(opts, "Pooling", Boolean.FalseString)) == true);\r
-        bool bUTF16 = (SQLiteConvert.ToBoolean(FindKey(opts, "UseUTF16Encoding", Boolean.FalseString)) == true);\r
+        bool usePooling = (SqliteConvert.ToBoolean(FindKey(opts, "Pooling", Boolean.FalseString)) == true);\r
+        bool bUTF16 = (SqliteConvert.ToBoolean(FindKey(opts, "UseUTF16Encoding", Boolean.FalseString)) == true);\r
         int maxPoolSize = Convert.ToInt32(FindKey(opts, "Max Pool Size", "100"));\r
 \r
         _defaultTimeout = Convert.ToInt32(FindKey(opts, "Default Timeout", "30"), CultureInfo.CurrentCulture);\r
@@ -829,17 +868,26 @@ namespace Mono.Data.Sqlite
 \r
         SQLiteOpenFlagsEnum flags = SQLiteOpenFlagsEnum.None;\r
 \r
-        if (SQLiteConvert.ToBoolean(FindKey(opts, "FailIfMissing", Boolean.FalseString)) == false)\r
-          flags |= SQLiteOpenFlagsEnum.Create;\r
-\r
-        if (SQLiteConvert.ToBoolean(FindKey(opts, "Read Only", Boolean.FalseString)) == true)\r
+        if (SqliteConvert.ToBoolean(FindKey(opts, "Read Only", Boolean.FalseString)) == true)\r
           flags |= SQLiteOpenFlagsEnum.ReadOnly;\r
-        else\r
+        else {\r
           flags |= SQLiteOpenFlagsEnum.ReadWrite;\r
-\r
+          if (SqliteConvert.ToBoolean(FindKey(opts, "FailIfMissing", Boolean.FalseString)) == false)\r
+            flags |= SQLiteOpenFlagsEnum.Create;\r
+        }\r
+       if (SqliteConvert.ToBoolean (FindKey (opts, "FileProtectionComplete", Boolean.FalseString)))\r
+               flags |= SQLiteOpenFlagsEnum.FileProtectionComplete;\r
+       if (SqliteConvert.ToBoolean (FindKey (opts, "FileProtectionCompleteUnlessOpen", Boolean.FalseString)))\r
+               flags |= SQLiteOpenFlagsEnum.FileProtectionCompleteUnlessOpen;\r
+       if (SqliteConvert.ToBoolean (FindKey (opts, "FileProtectionCompleteUntilFirstUserAuthentication", Boolean.FalseString)))\r
+               flags |= SQLiteOpenFlagsEnum.FileProtectionCompleteUntilFirstUserAuthentication;\r
+       if (SqliteConvert.ToBoolean (FindKey (opts, "FileProtectionNone", Boolean.FalseString)))\r
+               flags |= SQLiteOpenFlagsEnum.FileProtectionNone;\r
+       \r
+                               \r
         _sql.Open(fileName, flags, maxPoolSize, usePooling);\r
 \r
-        _binaryGuid = (SQLiteConvert.ToBoolean(FindKey(opts, "BinaryGUID", Boolean.TrueString)) == true);\r
+        _binaryGuid = (SqliteConvert.ToBoolean(FindKey(opts, "BinaryGUID", Boolean.TrueString)) == true);\r
 \r
         string password = FindKey(opts, "Password", null);\r
 \r
@@ -854,7 +902,7 @@ namespace Mono.Data.Sqlite
         OnStateChange(ConnectionState.Open);\r
         _version++;\r
 \r
-        using (SQLiteCommand cmd = CreateCommand())\r
+        using (SqliteCommand cmd = CreateCommand())\r
         {\r
           string defValue;\r
 \r
@@ -876,7 +924,7 @@ namespace Mono.Data.Sqlite
           }\r
 \r
           defValue = FindKey(opts, "Legacy Format", Boolean.FalseString);\r
-          cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA legacy_file_format={0}", SQLiteConvert.ToBoolean(defValue) == true ? "ON" : "OFF");\r
+          cmd.CommandText = String.Format(CultureInfo.InvariantCulture, "PRAGMA legacy_file_format={0}", SqliteConvert.ToBoolean(defValue) == true ? "ON" : "OFF");\r
           cmd.ExecuteNonQuery();\r
 \r
           defValue = FindKey(opts, "Synchronous", "Normal");\r
@@ -911,11 +959,11 @@ namespace Mono.Data.Sqlite
           _sql.SetRollbackHook(_rollbackCallback);\r
 \r
 #if !PLATFORM_COMPACTFRAMEWORK\r
-        if (global::System.Transactions.Transaction.Current != null && SQLiteConvert.ToBoolean(FindKey(opts, "Enlist", Boolean.TrueString)) == true)\r
+        if (global::System.Transactions.Transaction.Current != null && SqliteConvert.ToBoolean(FindKey(opts, "Enlist", Boolean.TrueString)) == true)\r
                EnlistTransaction(global::System.Transactions.Transaction.Current);\r
 #endif\r
       }\r
-      catch (SQLiteException)\r
+      catch (SqliteException)\r
       {\r
         Close();\r
         throw;\r
@@ -924,7 +972,7 @@ namespace Mono.Data.Sqlite
 \r
     /// <summary>\r
     /// Gets/sets the default command timeout for newly-created commands.  This is especially useful for \r
-    /// commands used internally such as inside a SQLiteTransaction, where setting the timeout is not possible.\r
+    /// commands used internally such as inside a SqliteTransaction, where setting the timeout is not possible.\r
     /// This can also be set in the ConnectionString with "Default Timeout"\r
     /// </summary>\r
     public int DefaultTimeout\r
@@ -1325,8 +1373,8 @@ namespace Mono.Data.Sqlite
 \r
       string master = (String.Compare(strCatalog, "temp", true, CultureInfo.InvariantCulture) == 0) ? _tempmasterdb : _masterdb;\r
 \r
-      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table' OR [type] LIKE 'view'", strCatalog, master), this))\r
-      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())\r
+      using (SqliteCommand cmdTables = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table' OR [type] LIKE 'view'", strCatalog, master), this))\r
+      using (SqliteDataReader rdTables = cmdTables.ExecuteReader())\r
       {\r
         while (rdTables.Read())\r
         {\r
@@ -1334,8 +1382,8 @@ namespace Mono.Data.Sqlite
           {\r
             try\r
             {\r
-              using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))\r
-              using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))\r
+              using (SqliteCommand cmd = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))\r
+              using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))\r
               using (DataTable tblSchema = rd.GetSchemaTable(true, true))\r
               {\r
                 foreach (DataRow schemaRow in tblSchema.Rows)\r
@@ -1355,7 +1403,7 @@ namespace Mono.Data.Sqlite
                     row["COLUMN_DEFAULT"] = schemaRow[SchemaTableOptionalColumn.DefaultValue];\r
                     row["IS_NULLABLE"] = schemaRow[SchemaTableColumn.AllowDBNull];\r
                     row["DATA_TYPE"] = schemaRow["DataTypeName"].ToString().ToLower(CultureInfo.InvariantCulture);\r
-                    row["EDM_TYPE"] = SQLiteConvert.DbTypeToTypeName((DbType)schemaRow[SchemaTableColumn.ProviderType]).ToString().ToLower(CultureInfo.InvariantCulture);\r
+                    row["EDM_TYPE"] = SqliteConvert.DbTypeToTypeName((DbType)schemaRow[SchemaTableColumn.ProviderType]).ToString().ToLower(CultureInfo.InvariantCulture);\r
                     row["CHARACTER_MAXIMUM_LENGTH"] = schemaRow[SchemaTableColumn.ColumnSize];\r
                     row["TABLE_SCHEMA"] = schemaRow[SchemaTableColumn.BaseSchemaName];\r
                     row["PRIMARY_KEY"] = schemaRow[SchemaTableColumn.IsKey];\r
@@ -1367,7 +1415,7 @@ namespace Mono.Data.Sqlite
                 }\r
               }\r
             }\r
-            catch(SQLiteException)\r
+            catch(SqliteException)\r
             {\r
             }\r
           }\r
@@ -1428,8 +1476,8 @@ namespace Mono.Data.Sqlite
 \r
       string master = (String.Compare(strCatalog, "temp", true, CultureInfo.InvariantCulture) == 0) ? _tempmasterdb : _masterdb;\r
       \r
-      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
-      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())\r
+      using (SqliteCommand cmdTables = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
+      using (SqliteDataReader rdTables = cmdTables.ExecuteReader())\r
       {\r
         while (rdTables.Read())\r
         {\r
@@ -1441,8 +1489,8 @@ namespace Mono.Data.Sqlite
             // Such indexes are not listed in the indexes list but count as indexes just the same.\r
             try\r
             {\r
-              using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))\r
-              using (SQLiteDataReader rdTable = cmdTable.ExecuteReader())\r
+              using (SqliteCommand cmdTable = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))\r
+              using (SqliteDataReader rdTable = cmdTable.ExecuteReader())\r
               {\r
                 while (rdTable.Read())\r
                 {\r
@@ -1457,7 +1505,7 @@ namespace Mono.Data.Sqlite
                 }\r
               }\r
             }\r
-            catch (SQLiteException)\r
+            catch (SqliteException)\r
             {\r
             }\r
             if (primaryKeys.Count == 1 && maybeRowId == true)\r
@@ -1483,8 +1531,8 @@ namespace Mono.Data.Sqlite
             // Now fetch all the rest of the indexes.\r
             try\r
             {\r
-              using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_list([{1}])", strCatalog, rdTables.GetString(2)), this))\r
-              using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())\r
+              using (SqliteCommand cmd = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_list([{1}])", strCatalog, rdTables.GetString(2)), this))\r
+              using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader())\r
               {\r
                 while (rd.Read())\r
                 {\r
@@ -1501,8 +1549,8 @@ namespace Mono.Data.Sqlite
                     row["PRIMARY_KEY"] = false;\r
 \r
                     // get the index definition\r
-                    using (SQLiteCommand cmdIndexes = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [name] LIKE '{1}'", strCatalog, rd.GetString(1).Replace("'", "''"), master), this))\r
-                    using (SQLiteDataReader rdIndexes = cmdIndexes.ExecuteReader())\r
+                    using (SqliteCommand cmdIndexes = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [name] LIKE '{1}'", strCatalog, rd.GetString(1).Replace("'", "''"), master), this))\r
+                    using (SqliteDataReader rdIndexes = cmdIndexes.ExecuteReader())\r
                     {\r
                       while (rdIndexes.Read())\r
                       {\r
@@ -1517,8 +1565,8 @@ namespace Mono.Data.Sqlite
                     // primary key, and all the columns in the given index match the primary key columns\r
                     if (primaryKeys.Count > 0 && rd.GetString(1).StartsWith("sqlite_autoindex_" + rdTables.GetString(2), StringComparison.InvariantCultureIgnoreCase) == true)\r
                     {\r
-                      using (SQLiteCommand cmdDetails = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rd.GetString(1)), this))\r
-                      using (SQLiteDataReader rdDetails = cmdDetails.ExecuteReader())\r
+                      using (SqliteCommand cmdDetails = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rd.GetString(1)), this))\r
+                      using (SqliteDataReader rdDetails = cmdDetails.ExecuteReader())\r
                       {\r
                         int nMatches = 0;\r
                         while (rdDetails.Read())\r
@@ -1543,7 +1591,7 @@ namespace Mono.Data.Sqlite
                 }\r
               }\r
             }\r
-            catch (SQLiteException)\r
+            catch (SqliteException)\r
             {\r
             }\r
           }\r
@@ -1574,8 +1622,8 @@ namespace Mono.Data.Sqlite
       if (String.IsNullOrEmpty(catalog)) catalog = "main";\r
       string master = (String.Compare(catalog, "temp", true, CultureInfo.InvariantCulture) == 0) ? _tempmasterdb : _masterdb;\r
 \r
-      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'trigger'", catalog, master), this))\r
-      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())\r
+      using (SqliteCommand cmd = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'trigger'", catalog, master), this))\r
+      using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader())\r
       {\r
         while (rd.Read())\r
         {\r
@@ -1629,8 +1677,8 @@ namespace Mono.Data.Sqlite
 \r
       string master = (String.Compare(strCatalog, "temp", true, CultureInfo.InvariantCulture) == 0) ? _tempmasterdb : _masterdb;\r
 \r
-      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
-      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())\r
+      using (SqliteCommand cmd = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
+      using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader())\r
       {\r
         while (rd.Read())\r
         {\r
@@ -1695,8 +1743,8 @@ namespace Mono.Data.Sqlite
 \r
       string master = (String.Compare(strCatalog, "temp", true, CultureInfo.InvariantCulture) == 0) ? _tempmasterdb : _masterdb;\r
 \r
-      using (SQLiteCommand cmd = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))\r
-      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())\r
+      using (SqliteCommand cmd = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))\r
+      using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader())\r
       {\r
         while (rd.Read())\r
         {\r
@@ -1744,8 +1792,8 @@ namespace Mono.Data.Sqlite
 \r
       tbl.BeginLoadData();\r
 \r
-      using (SQLiteCommand cmd = new SQLiteCommand("PRAGMA database_list", this))\r
-      using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())\r
+      using (SqliteCommand cmd = new SqliteCommand("PRAGMA database_list", this))\r
+      using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader())\r
       {\r
         while (rd.Read())\r
         {\r
@@ -1844,8 +1892,8 @@ namespace Mono.Data.Sqlite
 \r
       tbl.BeginLoadData();\r
 \r
-      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
-      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())\r
+      using (SqliteCommand cmdTables = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
+      using (SqliteDataReader rdTables = cmdTables.ExecuteReader())\r
       {\r
         while (rdTables.Read())\r
         {\r
@@ -1855,8 +1903,8 @@ namespace Mono.Data.Sqlite
           {\r
             try\r
             {\r
-              using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))\r
-              using (SQLiteDataReader rdTable = cmdTable.ExecuteReader())\r
+              using (SqliteCommand cmdTable = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].table_info([{1}])", strCatalog, rdTables.GetString(2)), this))\r
+              using (SqliteDataReader rdTable = cmdTable.ExecuteReader())\r
               {\r
                 while (rdTable.Read())\r
                 {\r
@@ -1870,7 +1918,7 @@ namespace Mono.Data.Sqlite
                 }\r
               }\r
             }\r
-            catch (SQLiteException)\r
+            catch (SqliteException)\r
             {\r
             }\r
             // This is a rowid row\r
@@ -1892,8 +1940,8 @@ namespace Mono.Data.Sqlite
                 tbl.Rows.Add(row);\r
             }\r
 \r
-            using (SQLiteCommand cmdIndexes = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [tbl_name] LIKE '{1}'", strCatalog, rdTables.GetString(2).Replace("'", "''"), master), this))\r
-            using (SQLiteDataReader rdIndexes = cmdIndexes.ExecuteReader())\r
+            using (SqliteCommand cmdIndexes = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{2}] WHERE [type] LIKE 'index' AND [tbl_name] LIKE '{1}'", strCatalog, rdTables.GetString(2).Replace("'", "''"), master), this))\r
+            using (SqliteDataReader rdIndexes = cmdIndexes.ExecuteReader())\r
             {\r
               while (rdIndexes.Read())\r
               {\r
@@ -1902,8 +1950,8 @@ namespace Mono.Data.Sqlite
                 {\r
                   try\r
                   {\r
-                    using (SQLiteCommand cmdIndex = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rdIndexes.GetString(1)), this))\r
-                    using (SQLiteDataReader rdIndex = cmdIndex.ExecuteReader())\r
+                    using (SqliteCommand cmdIndex = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].index_info([{1}])", strCatalog, rdIndexes.GetString(1)), this))\r
+                    using (SqliteDataReader rdIndex = cmdIndex.ExecuteReader())\r
                     {\r
                       while (rdIndex.Read())\r
                       {\r
@@ -1934,7 +1982,7 @@ namespace Mono.Data.Sqlite
                       }\r
                     }\r
                   }\r
-                  catch (SQLiteException)\r
+                  catch (SqliteException)\r
                   {\r
                   }\r
                 }\r
@@ -2002,14 +2050,14 @@ namespace Mono.Data.Sqlite
       \r
       tbl.BeginLoadData();\r
 \r
-      using (SQLiteCommand cmdViews = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))\r
-      using (SQLiteDataReader rdViews = cmdViews.ExecuteReader())\r
+      using (SqliteCommand cmdViews = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))\r
+      using (SqliteDataReader rdViews = cmdViews.ExecuteReader())\r
       {\r
         while (rdViews.Read())\r
         {\r
           if (String.IsNullOrEmpty(strView) || String.Compare(strView, rdViews.GetString(2), true, CultureInfo.InvariantCulture) == 0)\r
           {\r
-            using (SQLiteCommand cmdViewSelect = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdViews.GetString(2)), this))\r
+            using (SqliteCommand cmdViewSelect = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdViews.GetString(2)), this))\r
             {\r
               strSql = rdViews.GetString(4).Replace('\r', ' ').Replace('\n', ' ').Replace('\t', ' ');\r
               n = CultureInfo.InvariantCulture.CompareInfo.IndexOf(strSql, " AS ", CompareOptions.IgnoreCase);\r
@@ -2018,9 +2066,9 @@ namespace Mono.Data.Sqlite
 \r
               strSql = strSql.Substring(n + 4);\r
 \r
-              using (SQLiteCommand cmd = new SQLiteCommand(strSql, this))\r
-              using (SQLiteDataReader rdViewSelect = cmdViewSelect.ExecuteReader(CommandBehavior.SchemaOnly))\r
-              using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))\r
+              using (SqliteCommand cmd = new SqliteCommand(strSql, this))\r
+              using (SqliteDataReader rdViewSelect = cmdViewSelect.ExecuteReader(CommandBehavior.SchemaOnly))\r
+              using (SqliteDataReader rd = (SqliteDataReader)cmd.ExecuteReader(CommandBehavior.SchemaOnly))\r
               using (DataTable tblSchemaView = rdViewSelect.GetSchemaTable(false, false))\r
               using (DataTable tblSchema = rd.GetSchemaTable(false, false))\r
               {\r
@@ -2045,8 +2093,8 @@ namespace Mono.Data.Sqlite
                     row["COLUMN_DEFAULT"] = viewRow[SchemaTableOptionalColumn.DefaultValue];\r
                     row["ORDINAL_POSITION"] = viewRow[SchemaTableColumn.ColumnOrdinal];\r
                     row["IS_NULLABLE"] = viewRow[SchemaTableColumn.AllowDBNull];\r
-                    row["DATA_TYPE"] = viewRow["DataTypeName"]; // SQLiteConvert.DbTypeToType((DbType)viewRow[SchemaTableColumn.ProviderType]).ToString();\r
-                    row["EDM_TYPE"] = SQLiteConvert.DbTypeToTypeName((DbType)viewRow[SchemaTableColumn.ProviderType]).ToString().ToLower(CultureInfo.InvariantCulture);\r
+                    row["DATA_TYPE"] = viewRow["DataTypeName"]; // SqliteConvert.DbTypeToType((DbType)viewRow[SchemaTableColumn.ProviderType]).ToString();\r
+                    row["EDM_TYPE"] = SqliteConvert.DbTypeToTypeName((DbType)viewRow[SchemaTableColumn.ProviderType]).ToString().ToLower(CultureInfo.InvariantCulture);\r
                     row["CHARACTER_MAXIMUM_LENGTH"] = viewRow[SchemaTableColumn.ColumnSize];\r
                     row["TABLE_SCHEMA"] = viewRow[SchemaTableColumn.BaseSchemaName];\r
                     row["PRIMARY_KEY"] = viewRow[SchemaTableColumn.IsKey];\r
@@ -2103,8 +2151,8 @@ namespace Mono.Data.Sqlite
 \r
       tbl.BeginLoadData();\r
 \r
-      using (SQLiteCommand cmdTables = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
-      using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())\r
+      using (SqliteCommand cmdTables = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))\r
+      using (SqliteDataReader rdTables = cmdTables.ExecuteReader())\r
       {\r
         while (rdTables.Read())\r
         {\r
@@ -2112,11 +2160,11 @@ namespace Mono.Data.Sqlite
           {\r
             try\r
             {\r
-              using (SQLiteCommandBuilder builder = new SQLiteCommandBuilder())\r
-              //using (SQLiteCommand cmdTable = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))\r
-              //using (SQLiteDataReader rdTable = cmdTable.ExecuteReader(CommandBehavior.SchemaOnly))\r
-              using (SQLiteCommand cmdKey = new SQLiteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].foreign_key_list([{1}])", strCatalog, rdTables.GetString(2)), this))\r
-              using (SQLiteDataReader rdKey = cmdKey.ExecuteReader())\r
+              using (SqliteCommandBuilder builder = new SqliteCommandBuilder())\r
+              //using (SqliteCommand cmdTable = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}]", strCatalog, rdTables.GetString(2)), this))\r
+              //using (SqliteDataReader rdTable = cmdTable.ExecuteReader(CommandBehavior.SchemaOnly))\r
+              using (SqliteCommand cmdKey = new SqliteCommand(String.Format(CultureInfo.InvariantCulture, "PRAGMA [{0}].foreign_key_list([{1}])", strCatalog, rdTables.GetString(2)), this))\r
+              using (SqliteDataReader rdKey = cmdKey.ExecuteReader())\r
               {\r
                 while (rdKey.Read())\r
                 {\r
@@ -2139,7 +2187,7 @@ namespace Mono.Data.Sqlite
                 }\r
               }\r
             }\r
-            catch (SQLiteException)\r
+            catch (SqliteException)\r
             {\r
             }\r
           }\r
@@ -2251,6 +2299,13 @@ namespace Mono.Data.Sqlite
     {\r
       _rollbackHandler(this, EventArgs.Empty);\r
     }\r
+\r
+    // http://www.sqlite.org/c3ref/config.html\r
+    public static void SetConfig (SQLiteConfig config)\r
+    {\r
+      int n = UnsafeNativeMethods.sqlite3_config (config);\r
+      if (n > 0) throw new SqliteException (n, null);\r
+    }\r
   }\r
 \r
   /// <summary>\r