I am modifying the N-10-KittensDb sample solution. I See how to create a SQLite database, but I wish to use an existing database. I am guessing that I need to copy the database to the proper UI data folder. Maybe it is done within the Core project? And if so how is the correct path injected into the running Exec? As the Core can be used across many UI's? What method is called to see if the database exists or needs to be copied?
Sample from DataService:
public DataService(ISQLiteConnectionFactory factory)
{
const string file = "Cats.sldb";
var connection = factory.Create(file);
connection.CreateTable<Kitten>();
}
I believe the paths are different for Android vs Phone vs Touch vs Wpf?
Please direct me to a sample piece of code that uses the Cirrious.MvvmCross.Plugins.Sqlite for Phone or Wpf.
Thank you Dan
Each platform by default creates a database in a folder location appropriate for the platform - e.g. Touch uses:
public ISQLiteConnection Create(string address)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return new SQLiteConnection(Path.Combine(path, address));
}
from https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/Sqlite/Cirrious.MvvmCross.Plugins.Sqlite.Touch/MvxTouchSQLiteConnectionFactory.cs#L18
To read/write files, MvvmCross does bundle a File plugin - this also operates by default in platform specific locations - but the two may not match perfectly - e.g. see:
protected override string FullPath(string path)
{
if (path.StartsWith(ResScheme))
return path.Substring(ResScheme.Length);
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), path);
}
from https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File.Touch/MvxTouchFileStore.cs#L22
Because of this mismatch, in order to share the same database-specific copy code across platforms you may find it easier to just inject your own platform specific copy on each platform - for more on injecting platform specific services, see http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With