C#,在 SQLite 数据库中存储 HTML 页面

发布于 2024-08-06 01:04:13 字数 283 浏览 4 评论 0原文

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

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

还有其他替代方案吗?

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

I want to cache large HTML pages in an SQLite database as blobs, but the HTML pages may ofcourse contain lots of characters which will corrupt the SQL statement.

I'm not too happy with performing search/replace to escape all characters messing up the SQL statement, and encoding the HTML to a format accepted by SQL seems like an expensive step, afterall I'm caching pages to speed things up.

Is there any other alternative for this?

I'm using the SQLite.NET provider

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-08-13 01:04:13

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

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

I would expect that if you used a named parameter to do the insert, the query engine would take care of escaping the necessary characters for you; eg(note, I've never used Sqlite, so this is a contrived sample):

var myCommand = SqliteCommand("INSERT INTO HtmlPages(PageName, PageText) VALUES(@PageName, @PageText)");
myCommand.Parameters.AddWithValue("@PageName", "asdf");
myCommand.Parameters.AddWithValue("@PageText", "<html>...</html>");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文