user

Shilpa

1 Mar 2022

SQLite3 Query: Unable to escape string with single quote characters while inserting into table.

General

I am using sqlite3 and created tables for the hybrid mobile applications. While executing insert query, it shows below error.

SQL error near line 16: near "s": syntax error

the line is,

INSERT INTO table_name (id, fullname) VALUES (98765, 'Robert O\'neils');

The issue is about escape character for a single quote. 

I also tried double escaping the single quote (using \\\' instead of \' ), but that ain't work either. 

What did I miss?

 

#sqlite #database

Comments

Rakshit

2 Mar 2022

Best Answer

best answer

Mysql syntax: Working sqlfiddle, Replace single quote with single backward slash ("\") as given below.

INSERT INTO mytable values('98765','Robert O\'neils');

 

Sqlite syntax: Working sqlfiddle, Replace a single quote with another single quote.

INSERT INTO table_name (id, fullname) VALUES (98765, 'Robert O''neils');

Replies

Shilpa

2 Mar 2022

github

Understood, the syntax is different in it! I see!

© 2024 Copyrights reserved for web-brackets.com