System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: ac0e253dcfaaaaf393d00a4ba743c1f927f9f185
Title: Opening ReadOnly fails
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Connection Resolution: Fixed
Last Modified: 2014-02-07 01:15:52
Version Found In:
Description:
Opening any database readonly fails every time.  It appears that the cause of this problem is that, unless "fail if missing" is specified in the connection string, the SQLITE_OPEN_CREATE flag is used.

Apparently earlier versions of the library allowed SQLITE_OPEN_READONLY|SQLITE_OPENC_REATE, but with the current version of the library that causes it to return SQLITE_MISUSE (seems reasonable, creating a file is decidedly NOT a readonly operation).

The connection opening code thus needs to be ammended to remove the CREATE flag if it is given the READONLY flag.

<hr /><i>anonymous added on 2011-02-11 18:06:11 UTC:</i><br />
<pre>
Index: System.Data.SQLite/SQLiteConnection.cs
===================================================================
--- System.Data.SQLite/SQLiteConnection.cs
+++ System.Data.SQLite/SQLiteConnection.cs
@@ -812,13 +812,16 @@
 
         if (SQLiteConvert.ToBoolean(FindKey(opts, "FailIfMissing", Boolean.FalseString)) == false)
           flags |= SQLiteOpenFlagsEnum.Create;
 
         if (SQLiteConvert.ToBoolean(FindKey(opts, "Read Only", Boolean.FalseString)) == true)
-          flags |= SQLiteOpenFlagsEnum.ReadOnly;
+        {
+            flags |= SQLiteOpenFlagsEnum.ReadOnly;
+            flags &= ~SQLiteOpenFlagsEnum.Create;
+        }
         else
-          flags |= SQLiteOpenFlagsEnum.ReadWrite;
+            flags |= SQLiteOpenFlagsEnum.ReadWrite;
 
         _sql.Open(fileName, flags, maxPoolSize, usePooling);
 
         _binaryGuid = (SQLiteConvert.ToBoolean(FindKey(opts, "BinaryGUID", Boolean.TrueString)) == true);
 
</pre>

<hr /><i>shane added on 2011-02-16 05:07:05 UTC:</i><br />
Modified Open() in SQLiteConnection.cs to remove the SQLiteOpenFlagsEnum.Create flag if "Read Only" is specified.