Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-482

SQL Server Schema Manager returns incorrect value for autoincrement on IDENTITY columns

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2, 2.3, 2.3.3
    • Fix Version/s: 2.3.4
    • Component/s: Schema Managers
    • Security Level: All
    • Environment:
      SQL Server

      Description

      When calculating table diffs, SQLServerSchemaManager returns column definitions for identity columns with _autoincrement set to FALSE.

      This causes the schema update SQL generation to pump out a
      ALTER TABLE x ALTER COLUMN id INT IDENTITY NOT NULL
      for every single identity column in the schema.

      The culprit is in DBAL\Schema\SQLServerSchemaManager, starting at line 43:

              $dbType = strtolower($tableColumn['TYPE_NAME']);
              $dbType = strtok($dbType, '(), ');
      
              $autoincrement = false;
              if (stripos($dbType, 'identity')) {
                  $dbType = trim(str_ireplace('identity', '', $dbType));
                  $autoincrement = true;
              }
      

      When the column in question is an identity int column, the TYPE_NAME is "int identity". The second line of the snippet drops the "identity" signifier, causing the following lines that determine autoincrement to do nothing.

      I simply moved the second line to below the autoincrement block ie:

              $dbType = strtolower($tableColumn['TYPE_NAME']);
      
              $autoincrement = false;
              if (stripos($dbType, 'identity')) {
                  $dbType = trim(str_ireplace('identity', '', $dbType));
                  $autoincrement = true;
              }
      
              $dbType = strtok($dbType, '(), ');
      

      This change solves this issue for me, and as far as I can tell, has no other consequences.

        Activity

        William Schaller created issue -
        Hide
        Benjamin Eberlei added a comment -

        Fixed for 2.3.4 and was fixed for 2.4 in a different way already.

        Show
        Benjamin Eberlei added a comment - Fixed for 2.3.4 and was fixed for 2.4 in a different way already.
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.4 [ 10421 ]
        Resolution Fixed [ 1 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-482, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            William Schaller
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: