doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.48k stars 1.34k forks source link

Dbtype sysname missing for SQLServerPlatform (when using change data capture) #6259

Open WrdVdb opened 10 months ago

WrdVdb commented 10 months ago

Bug Report

We have enabled cdc (change data capture) on our SQLserver database. And now we get the error

Unknown database type sysname requested, Doctrine\DBAL\Platforms\SQLServer2012Platform may not support it.

doctrine/dbal 3.7.2

Summary

Dump of field:

array:12 [
  "table_name" => "change_tables"
  "schema_name" => "cdc"
  "name" => "capture_instance"
  "type" => "sysname"
  "length" => "256"
  "notnull" => "1"
  "default" => null
  "scale" => "0"
  "precision" => "0"
  "autoincrement" => "0"
  "collation" => "Latin1_General_CI_AS"
  "comment" => null
]

When I add "'sysname' => Types::STRING," to the file vendor/doctrine/dbal/src/Platforms/SQLServerPlatform.php the problem is fixed.

$this->doctrineTypeMapping = [
            'bigint'           => Types::BIGINT,
            'binary'           => Types::BINARY,
            'bit'              => Types::BOOLEAN,
            'blob'             => Types::BLOB,
            'char'             => Types::STRING,
            'date'             => Types::DATE_MUTABLE,
            'datetime'         => Types::DATETIME_MUTABLE,
            'datetime2'        => Types::DATETIME_MUTABLE,
            'datetimeoffset'   => Types::DATETIMETZ_MUTABLE,
            'decimal'          => Types::DECIMAL,
            'double'           => Types::FLOAT,
            'double precision' => Types::FLOAT,
            'float'            => Types::FLOAT,
            'image'            => Types::BLOB,
            'int'              => Types::INTEGER,
            'money'            => Types::INTEGER,
            'nchar'            => Types::STRING,
            'ntext'            => Types::TEXT,
            'numeric'          => Types::DECIMAL,
            'nvarchar'         => Types::STRING,
            'real'             => Types::FLOAT,
            'smalldatetime'    => Types::DATETIME_MUTABLE,
            'smallint'         => Types::SMALLINT,
            'smallmoney'       => Types::INTEGER,
            'text'             => Types::TEXT,
            'time'             => Types::TIME_MUTABLE,
            'tinyint'          => Types::SMALLINT,
            'uniqueidentifier' => Types::GUID,
            'varbinary'        => Types::BINARY,
            'varchar'          => Types::STRING,
            'sysname'          => Types::STRING,
        ];

How to reproduce

Error happens after enabling cdc in the database.

Expected behaviour

No errors when saving records.

WrdVdb commented 10 months ago
--- /dev/null
+++ ../src/Platforms/SQLServerPlatform.php
@@ -1548,6 +1548,7 @@
             'uniqueidentifier' => Types::GUID,
             'varbinary'        => Types::BINARY,
             'varchar'          => Types::STRING,
+            'sysname'          => Types::STRING,
         ];
     }
derrabus commented 9 months ago

Please send a PR.

patrick1100 commented 4 months ago

I didn't find a PR and the problem still happen in doctrine/3.8.6. It's the PR's fault that it hasn't been fixed yet?

derrabus commented 4 months ago

I didn't find a PR and the problem still happen in doctrine/3.8.6. It's the PR's fault that it hasn't been fixed yet?

Kinda. Bugs don't fix themselves, you know. Somebody has to do it.