1
A
回答
2
沒有找到這方面的任何內置的解決方案,所以我通過具有關鍵的全局表解決了它,值對
這裏是我用來包裝這個很好的C#類
public class SQLiteVariable
{
public SQLiteVariable() : this (null, string.Empty)
{}
public SQLiteVariable(SQLiteConnection connection) : this(connection, string.Empty)
{}
public SQLiteVariable(string name) : this(null, name)
{}
public SQLiteVariable(SQLiteConnection connection, string name)
{
Connection = connection;
Name = name;
}
/// <summary>
/// The table name used for storing the database variables
/// </summary>
private const string VariablesTable = "__GlobalDatabaseVariablesTable";
/// <summary>
/// Gets or sets the SQLite database connection.
/// </summary>
/// <value>The connection.</value>
public SQLiteConnection Connection { get; set; }
/// <summary>
/// Gets or sets the SQLite variable name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the SQLite variable value.
/// </summary>
/// <value>The value.</value>
public string Value
{
get
{
CheckEnviornemnt();
var cmd = new SQLiteCommand(Connection)
{
CommandText = "SELECT Value FROM " + VariablesTable + " WHERE [email protected]"
};
cmd.Parameters.Add(new SQLiteParameter("@VarName", Name));
var returnValue = cmd.ExecuteScalar();
return returnValue as string;
}
set
{
CheckEnviornemnt();
// Assume the variable exists and do an update
var cmd = new SQLiteCommand(Connection)
{
CommandText = "INSERT OR REPLACE INTO " + VariablesTable + " (Key, Value) VALUES(@VarName, @Value)"
};
cmd.Parameters.Add(new SQLiteParameter("@Value", value));
cmd.Parameters.Add(new SQLiteParameter("@VarName", Name));
var count = cmd.ExecuteNonQuery();
}
}
private void CheckEnviornemnt()
{
if (Connection == null) throw new ArgumentException("Connection was not initialized");
var cmd = new SQLiteCommand(Connection)
{
CommandText = "CREATE TABLE IF NOT EXISTS "+VariablesTable+" (Key VARCHAR(30) PRIMARY KEY, Value VARCHAR(256));"
};
cmd.ExecuteNonQuery();
}
}
相關問題
- 1. sqlite變量
- 2. 在SQLite中比較變量
- 3. 模擬sqlite中的變量列名
- 4. sqlite全局變量bug
- 5. 將變量更新到sqlite
- 6. 在SQLite查詢中使用變量
- 7. 在Python中傳遞SQLite變量
- 8. SQLite中聲明變量,並用它
- 9. 在SQLite中存儲一次性變量
- 10. 如何在sqlite中使用變量
- 11. 的Python SQLite的插入來自變量
- 12. AngularJs + Sqlite - 在sqlite回調函數中填充變量
- 13. sqlite的格式文本與變量值
- 14. 給SQLite一個變量名的方法
- 15. 插入到變量使用javascript的SQLite
- 16. Sqlite python更新變量的空列
- 17. SQLite中的向量/列表
- 18. 在SQLite中重建變量的最簡單的方法
- 19. SQLite選擇從哪裏x變量
- 20. Android SQLite和綁定變量問題
- 21. 單行SQLite查詢SET變量
- 22. 調用變量到一個sqlite行
- 23. 使用Python變量組裝SQLite查詢
- 24. 將變量插入sqlite數據庫表
- 25. 在Android上使用SQLite綁定變量
- 26. 更新SQLite表,JS,PhoneGap,傳遞變量
- 27. 變量中的變量?
- 28. Javascript中的「變量」變量?
- 29. OOP中的變量變量
- 30. 變量中的PHP變量