-
Notifications
You must be signed in to change notification settings - Fork 934
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
fredericDelaporte
merged 3 commits into
nhibernate:master
from
fredericDelaporte:NH-4088
Oct 9, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
#endregion | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those |
||
} | ||
|
||
string result = _typeNames.Get(sqlType.DbType); | ||
if (result == null) | ||
{ | ||
throw new HibernateException(string.Format("No default type mapping for SqlType {0}", sqlType)); | ||
} | ||
|
||
return result; | ||
return _typeNames.Get(sqlType.DbType); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -239,12 +235,7 @@ public virtual string GetTypeName(SqlType sqlType) | |
/// <returns>The database type name used by ddl.</returns> | ||
public virtual string GetTypeName(SqlType sqlType, int length, int precision, int scale) | ||
{ | ||
string result = _typeNames.Get(sqlType.DbType, length, precision, scale); | ||
if (result == null) | ||
{ | ||
throw new HibernateException(string.Format("No type mapping for SqlType {0} of length {1}", sqlType, length)); | ||
} | ||
return result; | ||
return _typeNames.Get(sqlType.DbType, length, precision, scale); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -257,15 +248,48 @@ public virtual string GetLongestTypeName(DbType dbType) | |
return _typeNames.GetLongest(dbType); | ||
} | ||
|
||
protected int DefaultCastLength { get; set; } | ||
protected byte DefaultCastPrecision { get; set; } | ||
protected byte DefaultCastScale { get; set; } | ||
|
||
/// <summary> | ||
/// Get the name of the database type appropriate for casting operations | ||
/// (via the CAST() SQL function) for the given <see cref="SqlType"/> typecode. | ||
/// </summary> | ||
/// <param name="sqlType">The <see cref="SqlType"/> typecode </param> | ||
/// <returns> The database type name </returns> | ||
public virtual string GetCastTypeName(SqlType sqlType) | ||
public virtual string GetCastTypeName(SqlType sqlType) => | ||
GetCastTypeName(sqlType, _typeNames); | ||
|
||
/// <summary> | ||
/// Get the name of the database type appropriate for casting operations | ||
/// (via the CAST() SQL function) for the given <see cref="SqlType"/> typecode. | ||
/// </summary> | ||
/// <param name="sqlType">The <see cref="SqlType"/> typecode.</param> | ||
/// <param name="castTypeNames">The source for type names.</param> | ||
/// <returns>The database type name.</returns> | ||
protected virtual string GetCastTypeName(SqlType sqlType, TypeNames castTypeNames) | ||
{ | ||
return GetTypeName(sqlType, Column.DefaultLength, Column.DefaultPrecision, Column.DefaultScale); | ||
if (sqlType.LengthDefined || sqlType.PrecisionDefined || sqlType.ScaleDefined) | ||
return castTypeNames.Get(sqlType.DbType, sqlType.Length, sqlType.Precision, sqlType.Scale); | ||
switch (sqlType.DbType) | ||
{ | ||
case DbType.Decimal: | ||
// We cannot know if the user needs its digit after or before the dot, so use a configurable | ||
// default. | ||
return castTypeNames.Get(DbType.Decimal, 0, DefaultCastPrecision, DefaultCastScale); | ||
case DbType.DateTime: | ||
case DbType.DateTime2: | ||
case DbType.DateTimeOffset: | ||
case DbType.Time: | ||
case DbType.Currency: | ||
// Use default for these, dialects are supposed to map them to max capacity | ||
return castTypeNames.Get(sqlType.DbType); | ||
default: | ||
// Other types are either length bound or not length/precision/scale bound. Otherwise they need to be | ||
// handled previously. | ||
return castTypeNames.Get(sqlType.DbType, DefaultCastLength, 0, 0); | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.