EntityFrameworkCore.FirebirdSQL icon indicating copy to clipboard operation
EntityFrameworkCore.FirebirdSQL copied to clipboard

Duplicate citation of table name in FbHistoryRepository.ExistsSql

Open krilbe opened this issue 7 years ago • 1 comments

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 avatar Jan 25 '19 14:01 krilbe

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

krilbe avatar Jan 29 '19 10:01 krilbe