【问题标题】:sqlite-pcl database initialization in android platformandroid平台的sqlite-pcl数据库初始化
【发布时间】:2014-12-15 04:23:11
【问题描述】:

我在 android 平台上使用 sqlite-pcl 有一个非常奇怪的情况......我有一个从 SQLiteConnection 继承的数据库类,我为我的数据库使用个人文件夹,在构造函数中我有一个检查是否存在,但通常当我再次启动应用程序时,不删除任何文件,它返回 false...

 public class ScannifyDatabase : SQLiteConnection
            {
       public static string DBPath
                {
                    get
                    {
                        string path =        System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                        return System.IO.Path.Combine(path, "Scaniff.db3");
                    }
                }
      public ScannifyDatabase(string path)
                : base(new SQLitePlatformAndroid(),path)
            {
                if (!TableExists())
                {
                 this.CreateTable<DocumentType>();
                 InitData();
                }
           }
       private bool TableExists()
            {
               // return this.TableExists();
                const string cmdText = "SELECT name FROM sqlite_master WHERE type='table' AND name=?";
                var cmd = this.CreateCommand(cmdText, typeof(DocumentType).Name);
                var res = !string.IsNullOrEmpty(cmd.ExecuteScalar<string>());
                return res;
            }

 }

问题是什么?

【问题讨论】:

    标签: sqlite xamarin xamarin.android android-sqlite


    【解决方案1】:

    在 Xamarin Studio 中,在 Preferences --> Android 下,确保选中“Preserve data/cache between application deploys”。 Visual Studio 中也有类似的设置。

    【讨论】:

      猜你喜欢
      • 2012-12-15
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      相关资源
      最近更新 更多