【问题标题】:C#, Storing HTML pages in an SQLite databaseC#,在 SQLite 数据库中存储 HTML 页面
【发布时间】:2010-11-30 18:04:54
【问题描述】:

我想在 SQLite 数据库中将大型 HTML 页面缓存为 blob,但 HTML 页面当然可能包含大量字符,这会破坏 SQL 语句。

我对执行搜索/替换来转义所有扰乱 SQL 语句的字符不太满意,并且将 HTML 编码为 SQL 接受的格式似乎是一个昂贵的步骤,毕竟我正在缓存页面以加快速度.

有没有其他选择?

我正在使用SQLite.NET 提供程序

【问题讨论】:

  • 你能做一些简单的事情吗,比如 base-64 编码 HTML,或者在存储之前对其进行 gzip 压缩?

标签: html system.data.sqlite blobs


【解决方案1】:

我希望如果您使用命名参数进行插入,查询引擎会为您转义必要的字符;例如(注意,我从未使用过 Sqlite,所以这是一个人为的示例):

var myCommand = SqliteCommand("INSERT INTO HtmlPages(PageName, PageText) VALUES(@PageName, @PageText)");
myCommand.Parameters.AddWithValue("@PageName", "asdf");
myCommand.Parameters.AddWithValue("@PageText", "<html>...</html>");

【讨论】:

    猜你喜欢
    • 2016-05-26
    • 2021-04-20
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多