Dotrine 1.2 中的用户定义例程?
我必须为我的 MySQL 数据库编写一个用户定义的例程(计算距离函数)。
- 是否可以在 yaml 架构文件中定义它?
在终端 mysql-client 中定义例程后,一切正常,直到“doctrine build-all-reload” - 函数被删除,这是可以理解的;
- 如何附加每次运行“build-all-reload”时执行的 sql 脚本?
对不起我的英语。 汤姆
I have to write an user-defined routine for my MySQL database (calculating distance function).
- Is it possible to define it in yaml schema file?
After defining routine in terminal mysql-client everything is ok until 'doctrine build-all-reload' - function is dropped, which is understandable;
- How can I attach a sql script which will be executed everytime I run 'build-all-reload'?
Sorry for my English.
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了一个解决方案(在某种程度上与您的解决方案类似),方法是将以下几行添加到我的doctrine.php文件中:
现在,每次我执行 ./doctrine build-all-reload 都会执行以下脚本:
这个解决方案可能并不优雅,但是对我有用:)
我不打算从 MySQL 更改数据库。
之后,我可以在 Doctrine 查询中使用 DIST 函数,它的工作速度比使用标准内置函数实现快几倍,而且更短。
而不是
感谢您的帮助。
I found a solution (similar to yours in some way) by adding following lines to my doctrine.php file:
Now, everytime I execute ./doctrine build-all-reload a following script is executed:
This solution is maybe not elegant, but works for me:)
I am not planning to change database from MySQL.
After that i can use DIST function in Doctrine Queries and it works several times faster than using standard build-in-function implementation, and is much shorter.
istead of
Thanks for your help.
我认为这可以通过教义行为来完成。
遵循我自己的博客文章 http://darrendev.blogspot。 com/2010/03/creating-doctrine-custom-behaviour-part.html,但使用 setUp() 而不是 setTableDefinition(),您可以使用此创建一个文件代码:
... 是您可以影响表创建的地方。您可以在 yaml 文件中附加此行为:
可能有一种简洁的学说方式可以在“...”部分中完成您需要的操作,但是在浏览了一下源代码之后,我不确定,所以,这在你的应用程序的生命周期中只完成一次,我个人会在 Doctrine 之外完成这一切:
函数 另一种方法是用 PHP 编写距离计算函数作为教义行为(扩展 Doctrine_Record_Listener);作为奖励,您可以获得数据库可移植性。但它将代码与 Doctrine 联系在一起,因此其他应用程序无法像使用 mysql 例程那样使用该函数。
I think this can be done with Doctrine behaviours.
Following my own blog post http://darrendev.blogspot.com/2010/03/creating-doctrine-custom-behaviour-part.html, but using setUp() instead of setTableDefinition(), you create a file with this code:
The ... is where you can influence table creation. You attach this behaviour in the yaml file with:
There may be a neat doctrine-way to do what you need in the "..." part, but after poking around the source code a bit I'm not sure and so, as this is only done once in the lifetime of your application, I'd personally do it all outside Doctrine:
P.S. Another approach is to write your distance-calculating function in PHP as a doctrine behaviour (extend Doctrine_Record_Listener); as a bonus you get database portability. But it ties the code to Doctrine, so other applications cannot use the function the way they can with an mysql routine.