I'm目前正在開發的iOS應用程序與Xamarin跑進一個奇怪的錯誤使用SQLite淨PCL:sqlite的淨PCL {SQLite.SQLiteException:近 「)」:語法錯誤
{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…}
錯誤occours當我要插入到下面的模型的表:
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);
}
ŧ他的DbFactory的代碼創建並保存我的sqlite的連接對象:
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語句,但不幸的是,sqlite連接對象的異步版本沒有提供跟蹤。
然後我試圖在同步版本相同的代碼與啓用跟蹤,這是結果:
insert into "Int32"() values()
嗯,這是很清楚爲什麼它isn't工作,但如何能產生這樣的說法?我錯過了什麼或者它是一個錯誤?
更新:是的,我使用了搜索功能,沒有任何情況適合我的問題。
'service.GetSumPerpetrationParts(immobilePerpetrationId)'''返回的是什麼類型?因爲那是你插入的東西。 – valdetero