FirebirdSQL / NETProvider

Firebird ADO.NET Data Provider
https://firebirdsql.org/en/net-provider/
Other
161 stars 66 forks source link

Varchar is not respecting MaxLength #1162

Closed abraluve closed 9 months ago

abraluve commented 9 months ago

Hi,

I noticed bug where CAST(xx AS VARCHAR(32765)) is not respecting MaxLength attribute/fluent-api.

Problem should be here https://github.com/FirebirdSQL/NETProvider/blob/cf461dcdb5e0eb4e016cf5343baa913b2e8dd1a8/src/FirebirdSql.EntityFrameworkCore.Firebird/Storage/Internal/FbSqlGenerationHelper.cs#L40

as there is constant value that sets it.

SQL query:

SELECT xxx
FROM tableXXX
WHERE ColumnWithLength10 = CAST(parameter_placeholder AS VARCHAR(32765))

Input parameter has length 10 characters. If CAST is removed query works. Maybe some workaround to turn off unnecessary casts? I wonder why is it there anyway as my input parameter_placeholder is string? and ColumnWithLength10 is defined as varchar(10).

cincuranet commented 9 months ago

You can turn off the cast via WithExplicitParameterTypes in options.

And there's no MaxLength for parameters. The other side of comparison is not always a table column.

abraluve commented 9 months ago

That works thanks.

I meant this setting image

cincuranet commented 9 months ago

Again. That's column, not parameter.