Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 51 additions & 37 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,42 +1483,48 @@ public int DeleteAll<T> ()
return count;
}

~SQLiteConnection ()
{
Dispose (false);
}

public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}

protected virtual void Dispose (bool disposing)
{
Close ();
}

public void Close ()
{
if (_open && Handle != NullHandle) {
try {
if (_mappings != null) {
foreach (var sqlInsertCommand in _mappings.Values) {
sqlInsertCommand.Dispose();
}
}
var r = SQLite3.Close (Handle);
if (r != SQLite3.Result.OK) {
string msg = SQLite3.GetErrmsg (Handle);
throw SQLiteException.New (r, msg);
}
}
finally {
Handle = NullHandle;
_open = false;
}
}
~SQLiteConnection ()
{
Dispose (false);
}

public void Dispose ()
{
Dispose(true);
GC.SuppressFinalize(this);
}

public void Close()
{
Dispose(true);
}

protected virtual void Dispose(bool disposing)
{
if (_open && Handle != NullHandle) {
try {
if (disposing) {
if (_mappings != null) {
foreach (var sqlInsertCommand in _mappings.Values){
sqlInsertCommand.Dispose();
}
}

var r = SQLite3.Close(Handle);
if (r != SQLite3.Result.OK)
{
string msg = SQLite3.GetErrmsg(Handle);
throw SQLiteException.New(r, msg);
}
} else {
SQLite3.Close2(Handle);
}
}
finally {
Handle = NullHandle;
_open = false;
}
}
}

void OnTableChanged (TableMapping table, NotifyTableChangedAction action)
Expand Down Expand Up @@ -2999,7 +3005,10 @@ public enum ConfigOption : int
public static extern Result EnableLoadExtension (IntPtr db, int onoff);

[DllImport("sqlite3", EntryPoint = "sqlite3_close", CallingConvention=CallingConvention.Cdecl)]
public static extern Result Close (IntPtr db);
public static extern Result Close (IntPtr db);

[DllImport("sqlite3", EntryPoint = "sqlite3_close_v2", CallingConvention = CallingConvention.Cdecl)]
public static extern Result Close2(IntPtr db);

[DllImport("sqlite3", EntryPoint = "sqlite3_initialize", CallingConvention=CallingConvention.Cdecl)]
public static extern Result Initialize();
Expand Down Expand Up @@ -3159,6 +3168,11 @@ public static Result Close(Sqlite3DatabaseHandle db)
return (Result)Sqlite3.sqlite3_close(db);
}

public static Result Close2(Sqlite3DatabaseHandle db)
{
return (Result)Sqlite3.sqlite3_close_v2(db);
}

public static Result BusyTimeout(Sqlite3DatabaseHandle db, int milliseconds)
{
return (Result)Sqlite3.sqlite3_busy_timeout(db, milliseconds);
Expand Down