Custom procedure in Doctrine 1.2?

I need to write a custom routine for my MySQL database (calculating the distance function).

  • Is it possible to define it in the yaml schema file?

After defining the procedure in the terminal mysql-client, everything is fine until the "doctrine build-all-reload" function is removed, which is understandable:

  • How can I add a sql script that will be executed every time I run 'build-all-reload'?

Sorry for my English. Tom

+3
source share
2 answers

I found a solution (similar to yours in some way) by adding the following lines to my doctrine.php file:

$q = file_get_contents('../configs/sql/routines.sql');
$conn = Doctrine_Manager::connection();
$conn->execute($q);

Now, every time I perform. / doctrine build-all-reload, the following script is executed:

DROP FUNCTION IF EXISTS DIST;
CREATE FUNCTION DIST (fi11 DOUBLE, ksi11 DOUBLE, fi22 DOUBLE, ksi22 DOUBLE)
  RETURNS DOUBLE
   DETERMINISTIC
    BEGIN
     DECLARE d DOUBLE;
     DECLARE fi1 DOUBLE;
     DECLARE fi2 DOUBLE;
     DECLARE ksi1 DOUBLE;
     DECLARE ksi2 DOUBLE;
     SET fi1 = PI()*(fi11)/180;
     SET fi2 = PI()*(fi22)/180;
     SET ksi1 = PI()*(ksi11)/180;
     SET ksi2 =PI()*(ksi22)/180;
     SET d = ACOS((SIN(fi1)*SIN(fi2))+(COS(fi1)*COS(fi2)*COS((ksi1-ksi2))))*6371.0;
     RETURN d;
    END;

, , , :) MySQL.

DIST Doctrine Queries, , , .

$q->where('DIST(a.lan, a.lon, b.lan, b.lon) < ?', array(2.0));

istead

$q->where('ACOS((SIN(...)... ... wrrrr ;-P ))*6371.0 < ?', array(2.0));

.

+1

, Doctrine.

http://darrendev.blogspot.com/2010/03/creating-doctrine-custom-behaviour-part.html, setUp() setTableDefinition(), :

class DarrenTestable extends Doctrine_Template{
    public function setUp(){
        ...
    }
}

..., . yaml :

ActsAs:
    DarrenTestable

, , , , "...", , , , , , :

  • MySQL
  • SQL .

P.S. , PHP ( Doctrine_Record_Listener); . Doctrine, , , mysql.

0

All Articles