【发布时间】:2013-02-08 02:44:24
【问题描述】:
对于我的应用程序,我试图在我的 SQLite 应用程序中存储一个字节数组,我正在以这种方式填充我的 SQLite 数据库:
public bool InsertMessage()
{
//create string SQl and fill it with the SQLite query for inserting a message.
string SQL = "Insert into ClockMessages(InsertDateTime, SendDateTime, Data) Values('"+ insertdatetime + "', null, '" + data + "');";
List<SQLiteParameter> pars = new List<SQLiteParameter>();
pars.Add(new SQLiteParameter("InsertDateTime", insertdatetime));
pars.Add(new SQLiteParameter("Data", data));
//send the SQl query and it's parameters to the SQLiteDatabase class
return SQLiteDatabase.ExecuteNonQuery(SQL, pars);
}
其中 InsertDateTime 是 DateTime.UtcNow,Data 是一个字节数组。此结果的输出导致字段数据包含: System.Byte[],我不能只在该字段中显示真正的字节数组,而不显示字符串吗?我在任何地方都使用 Byte[] 类型来填充数据库,因此我不会将其转换为字符串。我想在Data字段中看到这样的内容:01、54、32、23、11、02、53。数据库中Data字段的DataType是:BLOB。
谁能帮我实现这个目标?
【问题讨论】:
-
您没有正确使用参数。您编写的代码容易受到 sql 注入的影响。
-
没关系,这个数据库是本地数据库,我知道要使用它的人,除了黑客/程序员等之外,他们什么都做
-
这种态度是最严重的安全漏洞。
-
如果他们应该在该数据库中进行 SQL 注入,则没有用户可能看不到的数据,因为这是来自他自己的数据和他自己进行的设置。
-
我很惊讶没有人注意到他在字符串中连接
insertdatetime和data而不是提供参数。