Home > Database > Mysql Tutorial > How Do I Escape Single Quotes in SQLite INSERT Statements?

How Do I Escape Single Quotes in SQLite INSERT Statements?

Linda Hamilton
Release: 2025-01-15 09:48:44
Original
489 people have browsed it

How Do I Escape Single Quotes in SQLite INSERT Statements?

Escape single quote characters in SQLite queries

Question

SQLite throws a syntax error when executing an INSERT statement within a string value that contains single quotes. Escape single quotes with backslash (') or double backslash (') does not solve this problem.

Answer

To escape single quote characters in SQLite queries, double the single quotes in the string value:

<code class="language-sql">INSERT INTO table_name (field1, field2) VALUES (123, 'Hello there''s');</code>
Copy after login

This is because SQLite expects single quotes as delimiters for string literals, and this is clearly stated in its documentation:

<code>字符串常量是用单引号 (') 括起来的字符串。字符串中的单引号可以通过连续使用两个单引号来编码——就像在 Pascal 中一样。不支持使用反斜杠字符的 C 样式转义,因为它们不是标准 SQL。</code>
Copy after login

The above is the detailed content of How Do I Escape Single Quotes in SQLite INSERT Statements?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template