2013-04-22 28 views
2

我正在使用MonoDroid將數據層從我的Window Mobile應用程序移植到Android和iOS。 我的數據層在SQL SERVER,SQL CE和Windows SQLite上運行並經過了很好的測試。SQLite沒有在MonoDroid和MonoTouch上正確存儲GUID值

我在我的Android解決方案中爲我的項目創建了類庫,並導入了我的所有代碼。 我創建了一個新的DbEngine實現來調整單聲道SQLite的查詢。

當我通過像插入到[user]值('xx','hello',null)'這樣的文本插入到表中時,它工作正常,並且我可以看到受影響的行數大於0. 但是,當我嘗試插入使用命令和參數,我得到不正確的值在GUID列請參閱截圖。

// Creating the parameter 
public override DbParameter CreateParameter(string name, object value) 
{ 
    DbParameter result; 
    if (value is byte[]) 
    { 
     var length = (value as Array).Length; 
     result = new SqliteParameter(name, DbType.Binary, length) { Value = value}; 
    } 
    else if (value is string && ((string)value).Length > 4000) 
    { 
     var length = ((string)value).Length; 
     result = new SqliteParameter(name, DbType.String, length) { Value = value }; 
    } 
    else if (value is Guid) 
    { 
     result = new SqliteParameter(name, DbType.Guid) { Value = value }; // up to here, I can see that the GUID has the right value and the SQLiteParameter is created properly. 
    } 
    else 
    { 
     result = new SqliteParameter(name, value); 
    } 
    return result; 
} 

這是作爲參數 enter image description here

回答

3

經過長期鬥爭過去了怎麼行插入,似乎GUID參數不支持Mono.Data.SQLite。 所有我需要解決的問題是在我的代碼,當我創造我檢查參數,如果它是GUID,我創建string類型的參數如下所示:

result = new SqliteParameter(name, value.ToString()); 

這工作正常,並妥善保存的值並用於查詢數據庫。 這是非常令人沮喪的,尤其是當Xamarin團隊告訴我這是一個Unicode問題:( 希望它可以幫助別人。)