Sql – Escape Single Quote Characters when Importing to SQLite

escapingquotessedsqlite

I have a records.txt file like this:

INSERT INTO 'blogtitles' VALUES('Kelly's at house');
INSERT INTO 'blogtitles' VALUES('Nice catch!');

When i try to import records.txt into the db: sqlite3 my.db < records.txt
It gives an error because of the first line.
I have many lines like this in the records.txt file.
I need a sed syntax that will escape all these single quotes within the strings. So there will not be any problem when importing.
I really need this 🙁
Thank you!

Best Answer

The SQL standard specifies that single-quotes in strings are escaped by putting two single quotes in a row. SQL works like the Pascal programming language in the regard. SQLite follows this standard. Example:

INSERT INTO xyz VALUES('5 O''clock');

link