dimanche 11 octobre 2015

How to add SQLiteOpenFlags.FullMutex flag in Xamarin iOS SQLite

I'm trying to use a SQLite database in my project accross multiple threads using a method discussed in the Xamarin forums. Within it they create the following static class:

public static class Data {
    static readonly string Path = System.IO.Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "database.db");
    static SQLite.SQLiteConnection connection;
    public static SQLite.SQLiteConnection Connection
    {
        get {
            if (connection == null) {
                connection = new SQLiteConnection (Path,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex , true);
            }
            return connection;
        }
    }
}

I am trying to implement this however the connection method I am currently using has a different method signature. I think this is because I'm using PCL. I currently connect using:

SQLiteConnection db = new SQLiteConnection (new SQLitePlatformIOS (), AppController._dbPath, false, null);

How do I add SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex so I can use the connection like:

new SQLiteConnection (Path,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex , true)

I've tired the following but it's failing as it's not matching the required method signature

_connection = new SQLiteConnection (new SQLitePlatformIOS (),Path,false,null,SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex);

Aucun commentaire:

Enregistrer un commentaire