如何安全地使用保留的SQL名称? [英] How to safely use reserved SQL names?
问题描述
我使用Cakephp 3使用sqlserver作为数据源服务器。我确定没有与我的数据库连接的问题..作为home.ctp提示,我连接到我的数据库..我还使用migrations插件创建我的表..似乎没有问题工作这些工具。但是我烤了我的MVC后,我只有页面满了错误..
I'm using Cakephp 3 using sqlserver as datasource server. I am sure there's no problem with my database connection.. as home.ctp prompts that I am connected to my database.. and I'm as well using migrations plugin to create my tables.. it seems like there is no problem working with these tools. but after I bake my MVC, I only got page full of errors..
例如
$ bin\cake烘烤所有测试
for example $bin\cake bake all tests
没有我发现的错误和MVC在其特定的文件夹,testController.php,testTable等。
there are no errors I found and MVC are in its specific folder, testController.php, testTable, etc.
和在浏览器
localhost:8765\tests
and in browsers localhost:8765\tests
但是我得到的是不同错误的页面..我看到了
but all I got is page of different errors.. Im seeing
错误:SQLSTATE [42000]:[Microsoft] [SQL Server Native Client 11.0] [SQL Server]关键字'desc'附近的语法不正确
SELECT * FROM(SELECT Tests.id AS [Tests__id],Tests.desc AS [Tests__desc],(ROW_NUMBER()OVER(ORDER BY ))AS [_cake_page_rownum_] FROM tests Tests)_cake_paging_ WHERE _cake_paging _._ cake_page_rownum_< =:c0
我假设这是因为控制器有错误的查询或由bake生成的查询只是为mysql。我只是想知道如何处理这个。有没有一个设置我忘了做?请指教。我是Cakephp的新人,英语不是我的母语,对不起,如果我不能正确地解释我的问题。提前感谢。
I assume this is because of controllers with wrong queries or queries generated by bake is for mysql only. I just wanna know how to deal with this. is there a setting I forgot to do? please advice. I am new to Cakephp, and English is not my native language, sorry if I can't explain my question properly. thanks in advance.
推荐答案
如Vishal Gajjar在评论中所提到的,您使用保留关键字 desc
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.
为了能够使用这样的保留单词,列名称需要正确引用,但是CakePHP 3在默认情况下不会自动引用,因为这是一个昂贵的操作。
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.
如果您坚持使用保留字,通过 app.php
配置中的 quoteIdentifiers
选项启用标识符引用, code> autoQuoting()方法。
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()
method of the DB driver.
参见
- http:// book .cakephp.org / 3.0 / en / orm / database-basics.html#identifier-quoting
- http://book.cakephp.org/3.0/en/appendices/orm-migration。 html#identifier-quoting-disabled-by-default
- http://book.cakephp.org/3.0/en/orm/database-basics.html#identifier-quoting
- http://book.cakephp.org/3.0/en/appendices/orm-migration.html#identifier-quoting-disabled-by-default
这篇关于如何安全地使用保留的SQL名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!