语言和开发规则: Difference between revisions

Jump to navigation Jump to search
Line 270: Line 270:
==SQL编码规则==
==SQL编码规则==


*别名/字段命名的使用
*使用别名/字段命名


在进行 select 时,可以使用别名来简化查询的编写和阅读:
在进行 select 时,可以使用别名来简化查询的编写和阅读:
Line 334: Line 334:
*使用 $db->ifsql 替代 IF SQL
*使用 $db->ifsql 替代 IF SQL


Do not include the IF into your forged SQL request. But use instead $db->ifsql() method to you will make a SQL IF that is compatible with all SQL databases.
不要在SQL查询中使用IF。请改用 $db->ifsql() 方法,您将创建一个与所有SQL数据库兼容的SQL IF。


*No DELETE CASCADE and ON UPDATE CASCADE
*不使用 DELETE CASCADE 和 UPDATE CASCADE


Such SQL instructions are forbidden because they bypass the business rules of the application bringing a lot of troubles out of control of the developers. For example, if there is a delete cascade between table A and B, when the application will execute the code to remove a record in A, the children into table B will also be removed. If there was a Dolibarr PHP trigger (for example bring by an external module) on the deletion of record of B (for example to validate the deletion or to execute a complementary action), the DELETE CASCADE will be executed without having the Dolibarr PHP trigger executed, missing the validation or actions of the PHP trigger of the module. All business rules must be implemented on the same side (so the server PHP side), this is the reason why business rules implemented on Database side are not allowed (same conclusion than the next point about Database triggers). Note that external modules can use them for links between Dolibarr tables and its module tables but a better recommanded solution is to use the trigger to implement the deletion of its table when a record of a parent official table is deleted.
禁止使用此类SQL语句,因为它们绕过了应用程序的业务规则,给开发人员带来了很多失控的麻烦。例如,如果表A和B之间存在 DELETE CASCADE,当应用程序运行代码删除A中的记录时,表B中的子项也将被删除。如果一个PHP Dolibarr触发器(例如,由外部模块提供)存在于B表记录的删除操作上(例如,验证删除或执行附加操作),则 DELETE CASCADE 将在不执行PHP Dolibarr触发器的情况下仅执行删除B表记录的操作,跳过了由外部模块的PHP Dolibarr触发器执行的验证或附带操作。因此,所有业务规则都必须在同一端(PHP服务器端)实现,这就是为什么不允许在数据库端实现业务规则的原因(与下一节关于数据库触发器的情况相同)。
 
请注意,外部模块可以将它们(DELETE CASCADE 和 UPDATE CASCADE)用于Dolibarr表及其模块表之间的链接,但最好的推荐解决方案是在删除父表的记录时使用 Dolibarr PHP 触发器来实现其子表记录的删除。


==Mysql 特点==
==Mysql 特点==
714

edits

Navigation menu