Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1503

Add support for executing custom SQL functions on custom types

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      I have created a custom type called point but need a way to have a function called on columns of this type when fetching / updating / inserting entities.

      For example:

      Consider I have an entity which has a column called the_geom

      This is associated with my custom type point

      A basic select statement for this entity is as follows:

      SELECT id, name, the_geom FROM points where id = 1

      The problem is the_geom is encoded and on the PHP side I want it in human readable form. I would like a way to specify custom functions on SELECT / INSERT / UPDATE for columns of this custom type.

      When selecting my entity I would like to execute the function ST_AsText(the_geom)

      SELECT id, ST_AsText(the_geom) FROM points where id = 1

      The same goes for updates and inserts. I would like to surround the column SQL with other custom functions, to encode my human readable text back to the encoded value for the DB.

      Possibly this could be integrated into Doctrine\DBAL\Types\Type ?

      // Modify the column SQL for insert
      public function getSqlInsertColumn(....)
      
      // Modify the column SQL for update
      public function getSqlUpdateColumn(....)
      
      // Modify the column SQL for select
      public function getSqlSelectColumn(....)
      
      // A possible example of getSqlSelectColumn(...)
      public function getSqlSelectColumn($doctrineSql)
      {
          // $doctrineSql == "p0_.the_geom"
          return 'ST_AsText(' . $doctrineSql . ')';
      }
      
      1. 022-doctrine-basic-entity-persister.diff
        5 kB
        Lars Strojny
      2. 024-doctrine-many-to-many-persister.diff
        3 kB
        Lars Strojny
      3. 025-doctrine-unit-of-work.diff
        2 kB
        Lars Strojny
      4. 029-doctrine-query.diff
        1 kB
        Lars Strojny
      5. doctrine-type.diff
        0.4 kB
        Benjamin Morel

        Issue Links

          Activity

          Hide
          Lars Strojny added a comment -

          As DBAL-53 has been closed as a duplicate of this one, I'm attaching our patches to make type conversion work

          Show
          Lars Strojny added a comment - As DBAL-53 has been closed as a duplicate of this one, I'm attaching our patches to make type conversion work
          Hide
          Benjamin Eberlei added a comment -

          Thanks Lars, this is something else what i would implement though.

          This ticket gets high priority for 2.2, i will implement and check in directly after 2.1 will be released end of next month.

          Show
          Benjamin Eberlei added a comment - Thanks Lars, this is something else what i would implement though. This ticket gets high priority for 2.2, i will implement and check in directly after 2.1 will be released end of next month.
          Hide
          Benjamin Morel added a comment -

          Added a missing type hint in DBAL\Types\Type.php

          Will this feature be implemented soon? convertToDatabaseValueSQL() and convertToPHPValueSQL() are not used anywhere yet...

          Show
          Benjamin Morel added a comment - Added a missing type hint in DBAL\Types\Type.php Will this feature be implemented soon? convertToDatabaseValueSQL() and convertToPHPValueSQL() are not used anywhere yet...
          Hide
          Benjamin Eberlei added a comment -

          Implemented.

          Show
          Benjamin Eberlei added a comment - Implemented.
          Hide
          Benjamin Morel added a comment -

          What about the missing type hint on convertToPHPValueSQL() ?

          Is there a reason for the inconsistency in these method declarations:

          public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
          public function convertToPHPValueSQL($sqlExpr, $platform)

          Show
          Benjamin Morel added a comment - What about the missing type hint on convertToPHPValueSQL() ? Is there a reason for the inconsistency in these method declarations: public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) public function convertToPHPValueSQL($sqlExpr, $platform)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Dylan Arnold
            • Votes:
              6 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: