Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-843

Doctrine DBAL getSchema() detect wrong text type (LONGTEXT instead of TEXT)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5
    • Component/s: Schema Managers
    • Security Level: All
    • Labels:
      None

      Description

      I created a database from Doctrine Schema (refer as "expected schema" in the text below) which worked fine. Later I need to compare the "expected schema" with the "current schema" from the database. While I am doing that I figured out the the SQL statements of both schemas differs. While the "expected schema" defines a TEXT type for a field, the "current schema" defines a LONGTEXT for the field.

      Here is what I am doing:
      $tableName = $schema->createTable('tableName');
      $tableName->addColumn('fieldName', 'text', array('length' => 65535, 'notnull' => FALSE));

      $currentSchema = $connection->getSchemaManager()->createSchema();
      $currentSQL = $currentSchema->toSql($connection->getPlatform());

      // CREATE TABLE tableName (fieldName LONGTEXT DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

      $expectedSchema = $this->getExpectedSchema();
      $expectedSQL = $expectedSchema->toSql($connection->getPlatform());
      // CREATE TABLE tableName (fieldName TEXT DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

      This happens because in Doctrine/DBAL/Schema/MySqlSchemaManager.php the type of text is detect correctly but the length is set to FALSE instead of 65535 and when it comes to create the SQL string from the schema it just returns LONGTEXT because the variable $length is FALSE (See Doctrine/DBAL/Platforms/MySqlPlatform::getClobTypeDeclarationSQL().

      I added a new case in MySqlSchemaManager::_getPortableTableColumnDefinition which set the length of text types to 65535 and it works. I don't know if this is the correct place in code to do that.

      Maybe you can point at the correct place and I will create a PR at Github.

        Issue Links

          Activity

          Hide
          Steve Müller added a comment -

          Stefano Kowalke which DBAL version are you using? As far as I can see the length is preserved for text type columns. See here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php#L131-L160

          Show
          Steve Müller added a comment - Stefano Kowalke which DBAL version are you using? As far as I can see the length is preserved for text type columns. See here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php#L131-L160
          Hide
          Stefano Kowalke added a comment - - edited

          But there is no length information inside $tableColumn['type']. While the value of INT type in $tableColumn['type'] is 'int(11)', the value for TEXT type is just 'text'.

          The number inside the parentheses is extracted in https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php#L111 for INT type but not for the TEXT type - line 111 returns and save FALSE in $length.

          Show
          Stefano Kowalke added a comment - - edited But there is no length information inside $tableColumn ['type'] . While the value of INT type in $tableColumn ['type'] is 'int(11)', the value for TEXT type is just 'text'. The number inside the parentheses is extracted in https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php#L111 for INT type but not for the TEXT type - line 111 returns and save FALSE in $length.
          Hide
          Steve Müller added a comment -
          Show
          Steve Müller added a comment - Patch supplied in PR: https://github.com/doctrine/dbal/pull/553
          Hide
          Stefano Kowalke added a comment -

          Thanks for taking care of this.

          Show
          Stefano Kowalke added a comment - Thanks for taking care of this.
          Hide
          Steve Müller added a comment -

          Thanks for reporting

          Show
          Steve Müller added a comment - Thanks for reporting
          Hide
          Doctrine Bot added a comment -

          A related Github Pull-Request [GH-553] was closed:
          https://github.com/doctrine/dbal/pull/553

          Show
          Doctrine Bot added a comment - A related Github Pull-Request [GH-553] was closed: https://github.com/doctrine/dbal/pull/553
          Show
          Steve Müller added a comment - Fixed in commit: https://github.com/doctrine/dbal/commit/ba61dd3d1cbeb5d1e3289d98408e085225045ac9

            People

            • Assignee:
              Steve Müller
              Reporter:
              Stefano Kowalke
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: