Xamarin.Android SQLite.NET重复列名:ID

时间:2016-08-10 08:16:20

标签: c# android sqlite xamarin

我正在使用Xite的跨平台数据库和SQLite,只有在发布模式时才会抛出。调试模式永远不会抛出此异常。

Xamarin caused by: android.runtime.JavaProxyThrowable: SQLite.SQLiteException: duplicate column name: ID
  at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) <0xa02a0d48 + 0x0005c> in <filename unknown>:0 
  at SQLite.SQLiteCommand.Prepare () <0xa02a0cc0 + 0x00023> in <filename unknown>:0 
  at SQLite.SQLiteCommand.ExecuteNonQuery () <0xa02a0a28 + 0x00023> in <filename unknown>:0 
  at SQLite.SQLiteConnection.Execute (System.String query, System.Object[] args) <0xa02a0548 + 0x0009f> in <filename unknown>:0 
  at SQLite.SQLiteConnection.MigrateTable (SQLite.TableMapping map) <0xa02a2bb8 + 0x00213> in <filename unknown>:0 
  at SQLite.SQLiteConnection.CreateTable (System.Type ty, CreateFlags createFlags) <0x9f25f170 + 0x004af> in <filename unknown>:0 
  at SQLite.SQLiteConnection.CreateTable[T] (CreateFlags createFlags) <0x9f25f0c0 + 0x0002b> in <filename unknown>:0 
  at lv.app.shared.DB.FailedUploadDBConn..ctor () <0x9f25a200 + 0x0005f> in <filename unknown>:0 
  at lv.app.android.services.InstantUploadService.OnCreate () <0x9f25a048 + 0x00027> in <filename unknown>:0 
  at Android.App.Service.n_OnCreate (IntPtr jnienv, IntPtr native__this) <0x9f259fe0 + 0x00037> in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:77405489-155e-4e61-bb78-110dfea670a3 (intptr,intptr)
    at md56f5b51080823ac84a85e457b8b35670a.InstantUploadService.n_onCreate(Native Method)
    at md56f5b51080823ac84a85e457b8b35670a.InstantUploadService.onCreate(InstantUploadService.java:30)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3280)
    at android.app.ActivityThread.access$1900(ActivityThread.java:181)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1565)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6145)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

模型定义如下:

public class FailedUpload
{
    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }

    [NotNull]
    public string Path { get; set; }

    [NotNull]
    public string FolderHash { get; set; }

    public FailedUpload () {}

    public FailedUpload (string path, string folderHash) {
        Path = path;
        FolderHash = folderHash;
    }
}

我定义了以下界面并在我的Android项目中实现了它:

public interface ISQLite
{
    SQLiteConnection Connection { get; }
    void Delete ();
}

然后我使用依赖服务来访问数据库:

public class FailedUploadDBConn
{
    SQLite.SQLiteConnection conn;

    public FailedUploadDBConn () {
        var dependency = DependencyService.Get<ISQLite> ();
        conn = dependency.Connection;
        conn.CreateTable<FailedUpload> (); //Exception gets thrown here.
    }

    //Other methods...

}

我应该做一些特定的事情,以防止在发布模式下发生异常,或者只是抓住它并且什么也不做,或者它是Xamarin或SQLite中的错误?

0 个答案:

没有答案