views:

241

answers:

1

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

+3  A: 

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>");
Chris Shaffer