How to safely use reserved SQL names?

你离开我真会死。 提交于 2019-11-27 02:18:26

As already mentioned by Vishal Gajjar in the comments, you are using the reserved keyword desc for your column name, hence the error, it's not bakes fault, it's yours.

In order to be able to use such reserved words, the column name needs to be quoted properly, however CakePHP 3 doesn't auto-quote by default anymore, as it's an expensive operation.

If you insist on using reserved words, enable identifier quoting via the quoteIdentifiers option in your app.php config, or enable it manually using the autoQuoting() (enableAutoQuoting() as of CakePHP 3.4) method of the DB driver.

See also

You can use this code before problematic query:

$this->Tests->connection()->driver()->autoQuoting(true);

and when you are finished you can turn auto quoting off:

$this->Tests->connection()->driver()->autoQuoting(false);

So bad performance would be only on problematic query.

Use this :

SELECT * FROM (SELECT Tests.id AS [Tests__id], Tests.[desc] AS [Tests__desc], 
(ROW_NUMBER() OVER (ORDER BY (SELECT NULL))) AS [_cake_page_rownum_] FROM tests Tests) _cake_paging_
WHERE _cake_paging_._cake_page_rownum_ <= :c0

If you do use a keyword, use it in square braces [ ]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!