sqlite-net-pcl {SQLite.SQLiteException: near ")": 语法错误

sqlite-net-pcl {SQLite.SQLiteException: near ")": syntax error

我目前正在使用 Xamarin 开发一个 iOS 应用程序,运行 使用 sqlite-net-pcl 出现 st运行ge 错误:

{SQLite.SQLiteException: near ")": syntax error   at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) [0x0001e] in <49ac49cfb94341128f6929b3ff2090ee>:0    at SQLite.PreparedSqlLiteInsertCommand.Prepare () [0x00011] in <49ac49cfb94341128f6929b…}

当我想插入以下型号的table时出现错误:

public class PPPCount
{
    public PPPCount()
    {
    }

    [PrimaryKey]
    public int Id { get; set; }
    public string PerpePartCount { get; set; }
}

调用代码如下:

try
{
    var con = await DbFactory.Instance();
    var perpetrationPartCount = await 
        service.GetSumPerpetrationParts(immobilePerpetrationId);

    var dbModel = await con.FindAsync<PPPCount>(immobilePerpetrationId);
    if (dbModel == null)
    {
        var model = new PPPCount();

        model.Id = immobilePerpetrationId;
        model.PerpePartCount = perpetrationPartCount;

        //This causes the exception!!!!
        await con.InsertAsync(perpetrationPartCount);
    }
    else
    {
        if (dbModel.PerpePartCount != perpetrationPartCount)
        {
            dbModel.PerpePartCount = perpetrationPartCount;
            await con.UpdateAsync(dbModel);
        }
    }
    return perpetrationPartCount;
}
catch (Exception e)
{
    //AlertHelper.ShowError(e.Message);
}

创建并保存我的 sqlite 连接对象的 DbFactory 代码:

public class DbFactory
{
    private static SQLiteAsyncConnection connection;

    public static async Task<SQLiteAsyncConnection> Instance()
    {
        if (connection == null)
        {
            bool deleteDb = false;
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var dbPath = System.IO.Path.Combine(folder, "..", "immotech_offline.db3");

            if (File.Exists(dbPath) && deleteDb)
            {
                File.Delete(dbPath);
            }

            connection = new SQLiteAsyncConnection(dbPath);

            try
            {

                await connection.CreateTableAsync<ImmobilePerpetration>();
                await connection.CreateTableAsync<Customer>();
                await connection.CreateTableAsync<PPPCount>();
            }
            catch (Exception e)
            {
                //TODO: Delete this part!
                int i = 0;
            }
        }

        return connection;
    }
}

最重要的是运行我可以毫无问题地使用其他两个模型! 我真的无法解释导致此错误的原因,我尝试启用跟踪以显示 SQL-Statements,但不幸的是,sqlite 连接对象的异步版本不提供跟踪。

然后我在启用跟踪的同步版本中尝试了相同的代码,结果如下:

insert  into "Int32"() values ()

嗯,这很清楚为什么它不起作用,但是如何生成这样的语句?我是不是错过了什么或者这是一个错误?

更新:是的,我使用了搜索功能,但没有适合我问题的案例。

应该这样:

await con.InsertAsync(perpetrationPartCount);

是:

await con.InsertAsync(model);

根据您的代码,我们无法判断 perpetrationPartCount 是什么类型。它可能不是 PPPCount,因此该实体可能不是问题所在。