[mono.data.sqlite] Using sqlite_close_v2 when available
authorMiguel de Icaza <miguel@gnome.org>
Wed, 23 Sep 2015 19:34:00 +0000 (15:34 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 23 Sep 2015 19:34:00 +0000 (15:34 -0400)
commitd07e9a199a3fd1993a10a03fe7e7736c8b53bba8
tree108b1e34187782b03d769cefe4ed0f78e975a363
parentbbd8a219345e0c2d629d39dba030975d0a639ff1
[mono.data.sqlite] Using sqlite_close_v2 when available

From Matthew Leibowitz (mattleibo)

This is the recommended function for garbage collected languages.
http://sqlite.org/c3ref/close.html

The sqlite3_close_v2() interface is intended for use with host
languages that are garbage collected, and where the order in which
destructors are called is arbitrary.

Falls back to old sqlite3_close if we are on an old system

Useful for ADO.NET where the connection os often closed, but the
commands are re-usable

Mostly visible on Windows operating systems

This snippet should fail with a System.IO.IOException using the
current build of Mono on Windows:

    string filename = "test_" + Guid.NewGuid ().ToString ("N") + ".db";
    SqliteConnection conn = new SqliteConnection ("Data Source=" + filename);
    conn.Open ();
    SqliteCommand cmd = conn.CreateCommand ();
    cmd.CommandText = "PRAGMA legacy_file_format;";
    cmd.ExecuteScalar ();
    // close connection before the command
    conn.Dispose ();
    // then close the command
    cmd.Dispose ();
    // the locks should be released, and we should be able to delete the database
    File.Delete (filename);
mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteBase.cs
mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/UnsafeNativeMethods.cs
mcs/class/Mono.Data.Sqlite/Test/SqliteConnectionTest.cs