Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-191

Case sensitive columnName's don't work anymore

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Since the Schema refactoring, misc case column names do not work again.

      <?php
      
      /**
       * @Entity @Table(name="user")
       */
      class User
      { 
          /** @Id @Column(name="userId", type="integer") @GeneratedValue(strategy="AUTO")  */
          public $id;
          
          /** @Column(name="name", type="string")  */
          public $name;
      }
      

      This crashes the SchemaTool when creating the database schema:

      SchemaTool: exception 'Doctrine\DBAL\Schema\SchemaException' with message 'An unknown column-name userId was given.' in .../doctrine/lib/Doctrine/DBAL/Schema/SchemaException.php:60

      This may be because of several strtolower calls, e.g. in Doctrine\DBAL\Schema\Table ("$columnName = strtolower($columnName);")

        Activity

        Hide
        Nico Kaiser added a comment -

        Ok, I understand. This sounds quite difficult... thanks for the background info, this always helps me to understand some of the Doctrine internals...

        As you said, for portability reasons it is not a good idea to rely on the users' knowledge about the database (i.e. to always use columnName's with the 'right' case), because in some cases columnNames are automatically generated... And with DBMs being configurable it may also be a bad idea to rely on Doctrine mapping casing behavior to DB drivers...

        Yet in my project there is the simple requirement to keep the existing database model and use DDC on top of it, i.e. especially not renaming columns or changing primary keys, etc.

        Show
        Nico Kaiser added a comment - Ok, I understand. This sounds quite difficult... thanks for the background info, this always helps me to understand some of the Doctrine internals... As you said, for portability reasons it is not a good idea to rely on the users' knowledge about the database (i.e. to always use columnName's with the 'right' case), because in some cases columnNames are automatically generated... And with DBMs being configurable it may also be a bad idea to rely on Doctrine mapping casing behavior to DB drivers... Yet in my project there is the simple requirement to keep the existing database model and use DDC on top of it, i.e. especially not renaming columns or changing primary keys, etc.
        Hide
        Roman S. Borschel added a comment -

        @Benjamin: Can you review my latest changeset?

        Also, I discovered this:

        $theJoinTable->createColumn( 
            $columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => false)
        );
        

        Doesnt that mean all foreign keys are nullable? shouldnt this be:

        $theJoinTable->createColumn( 
            $columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => ! $joinColumn['nullable'])
        );
        

        ?

        Show
        Roman S. Borschel added a comment - @Benjamin: Can you review my latest changeset? Also, I discovered this: $theJoinTable->createColumn( $columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => false ) ); Doesnt that mean all foreign keys are nullable? shouldnt this be: $theJoinTable->createColumn( $columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => ! $joinColumn['nullable']) ); ?
        Hide
        Roman S. Borschel added a comment -

        Can this be considered fixed now?

        Show
        Roman S. Borschel added a comment - Can this be considered fixed now?
        Hide
        Nico Kaiser added a comment -

        Looks good!

        Show
        Nico Kaiser added a comment - Looks good!
        Hide
        Phansys added a comment -

        How can I get PostgreSQL case sensitive quoted columns works?

        My table structure is like this:

        CREATE TABLE "Author"
        (
        "IdAuthor" serial NOT NULL,
        "Name" character varying(100) NOT NULL DEFAULT ''::character varying,
        "CreationDate" timestamp without time zone,
        "ModificationDate" timestamp without time zone,
        CONSTRAINT "Author_pkey" PRIMARY KEY ("IdAuthor")
        )
        WITH (
        OIDS=FALSE
        );

        And in php...

        <?php
        // $em instanceof EntityManager
        $q = $em->createQuery('select a from MyDomain\Model\Author a where a."IdAuthor" = 1');
        $author = $q->getResult();

        and this returns the exception:

        [Syntax Error] line 0, col 56: Error: Expected =, <, <=, <>, >, >=, !=, got 'IdAuthor'

        Sorry if it's a wrong place to do de question; and many thanks for your help.
        Best regards.

        Show
        Phansys added a comment - How can I get PostgreSQL case sensitive quoted columns works? My table structure is like this: CREATE TABLE "Author" ( "IdAuthor" serial NOT NULL, "Name" character varying(100) NOT NULL DEFAULT ''::character varying, "CreationDate" timestamp without time zone, "ModificationDate" timestamp without time zone, CONSTRAINT "Author_pkey" PRIMARY KEY ("IdAuthor") ) WITH ( OIDS=FALSE ); And in php... <?php // $em instanceof EntityManager $q = $em->createQuery('select a from MyDomain\Model\Author a where a."IdAuthor" = 1'); $author = $q->getResult(); and this returns the exception: [Syntax Error] line 0, col 56: Error: Expected =, <, <=, <>, >, >=, !=, got 'IdAuthor' Sorry if it's a wrong place to do de question; and many thanks for your help. Best regards.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Nico Kaiser
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: