我目前正在用c#开发自己的密码管理器。
我的更新功能有问题:
protected internal bool Update()
{
// the updatestring that gets insert into the sqlitecommand
string updatestring = "";
// the affected rows returned by ExecuteNonQuery()
int affectedrows = 0;
try
{
using (SQLiteConnection connection = GetDatabaseConnection())
{
int i = 1;
// looping trough the dictionary that holds the data of the table
foreach (KeyValuePair<string, dynamic> keyValuePair in ArrData)
{
// format the update value e.g: Id = @Id
updatestring += String.Format("{0} = @{1}", keyValuePair.Key, keyValuePair.Key);
// if its not the last value to be updated add a , to the string
if (i < ArrData.Count)
{
updatestring += ", ";
}
i++;
}
connection.Open();
// building the commandtext TableName is set by the child class
SQLiteCommand sqLiteCommand = new SQLiteCommand(String.Format("UPDATE {0} SET ({1})", TableName, updatestring), connection);
sqLiteCommand.CommandType = System.Data.CommandType.Text;
// again looping trough the dictionary to add the parameters to the command
foreach (KeyValuePair<string, dynamic> keyValuePair in ArrData)
{
sqLiteCommand.Parameters.Add(new SQLiteParameter("@" + keyValuePair.Key, keyValuePair.Value));
}
affectedrows = sqLiteCommand.ExecuteNonQuery();
connection.Close();
}
}
catch (SQLiteException ex)
{
MessageBox.Show("Update" + Environment.NewLine + ex.Message);
return false;
}
return affectedrows > 0 ? true : false;
}
我正在使用libsodium加密敏感数据。 加密后,我使用base64对byte []进行编码。 这里的问题是,sqlite不会在我的base64编码变量中转义'='符号。
它抛出一个错误,说我在'='附近有一个sql逻辑错误
你们有解决这类问题的聪明方法吗?