ralmsdeveloper / EntityFrameworkCore.FirebirdSQL

FirebirdSQL database provider for Entity Framework Core.
Other
44 stars 26 forks source link

Duplicate citation of table name in FbHistoryRepository.ExistsSql #47

Open krilbe opened 5 years ago

krilbe commented 5 years ago

The issue

SQL generated to check existence of a table puts single quotes around the tabel name string literal returned by stringTypeMapping.GenerateSqlLiteral(TableName), which it should not.

Steps to reproduce

We encounter this when trying to execute migration, when an attempt is made to check for the table __EFMigrationsHistory. This is SQL we get:

SELECT COUNT(*)
FROM rdb$relations r
WHERE
    COALESCE(r.rdb$system_flag, 0) = 0
    AND
    rdb$view_blr IS NULL
    AND
    rdb$relation_name = '_UTF8'__EFMigrationsHistory''

Notice that there are single quotes around the table name itself (from GenerateSqlLiteral(...)) as well as around the _UTF8 refixed complete literal.

Further technical details

EntityFrameworkCore.FirebirdSql version: 2.1.4

Suggested fix

In FbHistoryRepository.cs, this code appears:

                return $@"
SELECT COUNT(*)
FROM rdb$relations r
WHERE
    COALESCE(r.rdb$system_flag, 0) = 0
    AND
    rdb$view_blr IS NULL
    AND
    rdb$relation_name = '{stringTypeMapping.GenerateSqlLiteral(TableName)}'";

It should be changed into:

                return $@"
SELECT COUNT(*)
FROM rdb$relations r
WHERE
    COALESCE(r.rdb$system_flag, 0) = 0
    AND
    rdb$view_blr IS NULL
    AND
    rdb$relation_name = {stringTypeMapping.GenerateSqlLiteral(TableName)}";
krilbe commented 5 years ago

We have tested this fix in our project, and it does work.