問題描述
MySQL 文檔說它應該是 \'
.但是,scite 和 mysql 都顯示 ''
有效.我看到了,它的工作原理.我該怎么辦?
您引用的 MySQL 文檔實際上比您提到的要多一些.它還說,
<塊引用>在用'
"引用的字符串中的'
"可以寫成''
".
(另外,您鏈接到 MySQL 5.0 版本的表 8.1.特殊字符轉(zhuǎn)義序列,當前版本是 5.6 — 但當前的 表 8.1.特殊字符轉(zhuǎn)義序列看起來非常相似.)>
我認為 Postgres 注釋backslash_quote (string)
參數(shù) 提供信息:
這控制引號是否可以在字符串文字中用 \'
表示.表示引號的首選 SQL 標準方式是將引號加倍 (''
),但 PostgreSQL 歷來也接受 \'
.但是,使用 \'
會帶來安全風險...
這對我說,與使用反斜杠轉(zhuǎn)義單引號相比,使用雙引號字符是更好的整體和長期選擇.
現(xiàn)在,如果您還想在等式中添加語言選擇、??SQL 數(shù)據(jù)庫及其非標準特性的選擇以及查詢框架的選擇,那么您最終可能會有不同的選擇.你沒有提供太多關(guān)于你的約束的信息.
The MySQL documentation says that it should be \'
. However, both scite and mysql shows that ''
works. I saw that and it works. What should I do?
The MySQL documentation you cite actually says a little bit more than you mention. It also says,
A "
'
" inside a string quoted with "'
" may be written as "''
".
(Also, you linked to the MySQL 5.0 version of Table 8.1. Special Character Escape Sequences, and the current version is 5.6 — but the current Table 8.1. Special Character Escape Sequences looks pretty similar.)
I think the Postgres note on the backslash_quote (string)
parameter is informative:
This controls whether a quote mark can be represented by
\'
in a string literal. The preferred, SQL-standard way to represent a quote mark is by doubling it (''
) but PostgreSQL has historically also accepted\'
. However, use of\'
creates security risks...
That says to me that using a doubled single-quote character is a better overall and long-term choice than using a backslash to escape the single-quote.
Now if you also want to add choice of language, choice of SQL database and its non-standard quirks, and choice of query framework to the equation, then you might end up with a different choice. You don't give much information about your constraints.
這篇關(guān)于如何在MySql中轉(zhuǎn)義撇號(')?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!