Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-4088 - Dialect.GetCastTypeName is buggy #709

Merged
merged 3 commits into from
Oct 9, 2017

Conversation

fredericDelaporte
Copy link
Member

NH-4088 - Dialect.GetCastTypeName is buggy

Fix TypeNames.Get for decimal capacity

  • Compare capacity against precision for precision based types
  • Fix dialects declarations for max precision
  • Fix dialects declarations for precision based types which were using length as precision or scale

Fix GetCastTypeName

  • Use type length/precision/scale when defined
  • Use maximal capacity types otherwise when it makes sens
  • Use configurable default length/precision/scale otherwise

 * Compare capacity against precision for precision based types
 * Fix dialects declarations for max precision
 * Fix dialects declarations for precision based types which were using length as precision or scale

It is a prerequisite to the fix of GetTypeCastName.
 * Use type length/precision/scale when defined
 * Use maximal capacity types otherwise when it makes sens
 * Use configurable default length/precision/scale otherwise
hazzik
hazzik previously approved these changes Oct 4, 2017
 * Oracle double special case
 * More tests
 * Tests fixes
Assert.Ignore("Applies only to Firebird");

_driver = new FirebirdClientDriver();
_driver.Configure(cfg.Properties);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was failing due to used driver not being configured.

var expectedCommandTxt = "select (case when col = @p0 then cast(@p1 as VARCHAR(255)) else cast(@p2 as VARCHAR(255)) end) from table";
Assert.That(cmd.CommandText, Is.EqualTo(expectedCommandTxt));
var expectedCommandTxt =
"select (case when col = @p0 then cast(@p1 as VARCHAR(4000)) else cast(@p2 as VARCHAR(4000)) end) from table";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also failing because still testing for VARCHAR(255) in resulting string, while the driver has been changed to use the default length instead of the supplied one for variable length string, due to the sql like issue otherwise.

@@ -199,6 +199,9 @@ private static Dialect InstantiateDialect(string dialectName, IDictionary<string
/// <param name="settings">The configuration settings.</param>
public virtual void Configure(IDictionary<string, string> settings)
{
DefaultCastLength = PropertiesHelper.GetInt32(Environment.QueryDefaultCastLength, settings, 4000);
DefaultCastPrecision = PropertiesHelper.GetByte(Environment.QueryDefaultCastPrecision, settings, null) ?? 28;
DefaultCastScale = PropertiesHelper.GetByte(Environment.QueryDefaultCastScale, settings, null) ?? 10;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some inconsistencies in those PropertiesHelper methods.

I think the right signature is the GetInt32 one, but completed with an overload yielding a nullable and not taking any default.

@@ -215,17 +218,10 @@ public virtual string GetTypeName(SqlType sqlType)
{
if (sqlType.LengthDefined || sqlType.PrecisionDefined || sqlType.ScaleDefined)
{
string resultWithLength = _typeNames.Get(sqlType.DbType, sqlType.Length, sqlType.Precision, sqlType.Scale);
if (resultWithLength != null) return resultWithLength;
return _typeNames.Get(sqlType.DbType, sqlType.Length, sqlType.Precision, sqlType.Scale);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those TypeNames methods are never yielding null. (Unless a Put was done with null, but now Put throws null argument exception if it is attempted.)

@@ -64,7 +63,7 @@ public MySQLDialect()
RegisterColumnType(DbType.String, 16777215, "MEDIUMTEXT");
//todo: future: add compatibility with decimal???
//An unpacked fixed-point number. Behaves like a CHAR column;
//unpacked means the number is stored as a string, using one character for each digit of the value.
//unpacked means the number is stored as a string, using one character for each digit of the value.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encoding change. The file was not UTF-8.

}
//Could not find a specific type for the capacity, using the default
return Replace(Get(typecode), size, precision, scale);
return Get(typecode);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default typenames are never supposed to have formatting placeholders.

@hazzik hazzik modified the milestones: 5.0, 5.1 Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants