10)The <identifier body> of a <regular identifier> is equivalent
to an <identifier body> in which every letter that is a lower-
case letter is replaced by the equivalent upper-case letter
or letters. This treatment includes determination of equiva-
lence, representation in the Information and Definition Schemas,
representation in the diagnostics area, and similar uses.
SQL 92
但是 SQL Standard 也允許你用雙引號(doublequote) 字元括起名稱,這時就會抑制大小寫轉換的動作。這是 SQL Standard 配合國際字元集所定的規則。在這種情形下,也 SQL Standard 也允許你用保留字做為欄位名稱。
還有一點,ZendFramework 的 Zend_Db_Select 類可以幫助你處理一些自行組成 SQL 敘述的事。因為 Zend_Db_Select 組成的 SQL 敘述會替欄位名稱和表格名稱加上雙括號。
(Zend_Db_Select 是一種 Active record pattern)
$db->select()->from('user');
就會組成:
SELECT * FROM "user";
如果你用那些 tool ,程式碼不需要改什麼。
Posted by 遊手好閒的石頭成
at 2008年05月5日 16:06
SQL 欄位加雙引號真的是標準嗎? MySQL 看起來不支援這個標準 XD
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"user"
LIMIT 0, 30' at line 1
Posted by ngo
at 2008年05月18日 15:57
注意看我倒數第二段,我寫「我最不喜歡的 MySQL方言」,原因就在於 MySQL 的內定語法並不符合 SQL標準。
Ok, 言歸正傳,我猜你忘了啟用 ANSI_QUOTES 。
參考 MySQL 5.1 Reference Manual::Schema Object Names: " The identifier quote character is the backtick (“`”).
If the ANSI_QUOTES SQL mode is enabled, it is also allowable to quote identifiers within double quotes"。