With MvvmCross, which is the preferred way to copy a pre-populated SQLite database

I am modifying the N-10-KittensDb solution. I see how to create a SQLite database, but I want to use an existing database. I assume that I need to copy the database to the appropriate user interface data folder. Maybe this was done as part of the Core project? And if so, how is the correct path introduced into the executable? How can Core be used in many user interfaces? Which method is called to see if the database exists or needs to be copied?

Example from DataService:

public DataService(ISQLiteConnectionFactory factory) { const string file = "Cats.sldb"; var connection = factory.Create(file); connection.CreateTable<Kitten>(); } 

I think the paths are different from Android vs Phone vs Touch vs Wpf?

Point me to a sample code that uses Cirrious.MvvmCross.Plugins.Sqlite for a phone or Wpf.

Thanks. Dan

+6
source share
1 answer

Each platform by default creates a database in a folder suitable for the platform - for example. 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 binds the File plugin - it also works by default in certain platform places, but these two may not coincide perfectly - for example, 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

Due to this inconsistency, in order to share the same copy code for a specific database on different platforms, it may be easier for you to simply enter your own platform-specific copy on each platform - for more information on using certain platform services, see http : //slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html

+3
source

Source: https://habr.com/ru/post/949506/


All Articles