System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: dd30ecb89d423c4cc53b2fd89d04f5e4ced673ee
Title: AccessViolationException during prepare
Status: Closed Type: Incident
Severity: Severe Priority: NextRelease
Subsystem: Native_Assembly Resolution: Core_Bug
Last Modified: 2016-08-25 00:39:32
Version Found In: 1.0.102.0
User Comments:
anonymous added on 2016-06-27 21:56:04:
Hi SQLite,

EXCEPTION:

An unhandled exception of type 'System.AccessViolationException' occurred in System.Data.SQLite.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

CALLSTACK:

   at System.Data.SQLite.UnsafeNativeMethods.sqlite3_prepare_interop(IntPtr db, IntPtr pSql, Int32 nBytes, IntPtr& stmt, IntPtr& ptrRemain, Int32& nRemain)
   at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at SQLiteConsoleTest.Program.Main(String[] args) in C:\Progetti\Utility\SQLiteConsoleTest\Program.cs:line 46
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

**********************
* CODE TO REPRODUCE: *
**********************

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQLiteConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            File.Delete("C:\\Database.db3");

            using (var conn = new SQLiteConnection("data source=C:\\Database.db3"))
            {
                conn.Open();

                using (var command = new SQLiteCommand(@"CREATE TABLE Men (Id integer PRIMARY KEY AUTOINCREMENT NOT NULL)", conn))
                    command.ExecuteNonQuery();

                using (var command = new SQLiteCommand(@"CREATE TABLE MenHouse ( 
                                                             Id integer PRIMARY KEY AUTOINCREMENT NOT NULL, 
                                                             IdMen integer NOT NULL COLLATE NOCASE, 
                                                              FOREIGN KEY (IdMen)
                                                                REFERENCES Men(Id)
                                                                ON DELETE RESTRICT
                                                                ON UPDATE RESTRICT)", conn))
                    command.ExecuteNonQuery();

                using (var command = new SQLiteCommand(@"CREATE TABLE MenHouseItems ( 
                                                             Id integer PRIMARY KEY AUTOINCREMENT NOT NULL, 
                                                             IdMenHouse integer NOT NULL COLLATE NOCASE, 
                                                              FOREIGN KEY (IdMenHouse)
                                                                REFERENCES MenHouse(Id)
                                                                ON DELETE RESTRICT
                                                                ON UPDATE RESTRICT)", conn))
                    command.ExecuteNonQuery();

                using (var command = new SQLiteCommand("SELECT * FROM [MenHouseItems] JOIN [MenHouse] AS [MenHouse] ON [MenHouseItems].[IdMenHouse] = [MenHouse].[Id] JOIN [Men] AS [Men] ON [MenHouse].[IdMen] = [Men].[Id] WHERE [Men].[Id] = 1 ORDER BY [Men].[Id] DESC", conn))
                {

                    using (var dataReader = command.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        while (dataReader.Read())
                        {


                        }
                    }
                }
            }
        }
    }
}

**********
** NOTE **
**********

The version 1.0.99.0 runs successfully. I tried on Windows 2012 R2 server and Windows 10/ all x64, Ms Framework: 4.6.1

sqlite-netFx46-static-binary-bundle-x64-2015-1.0.102.0

mistachkin added on 2016-07-01 22:14:48:
This issue has been fixed upstream in the SQLite core library.  The fix will be
present in the 1.0.103.0 release.

See: [https://www.sqlite.org/src/info/e8d439c77685eca6]