-
Notifications
You must be signed in to change notification settings - Fork 934
Adjust string parameter sizes for MSSQL #1844
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
Conversation
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.
This looks great.
As I understand it, a Linq query using something like x.MappedAs(NHibernate.Type.TypeFactory.Basic("AnsiString(200)"))
would also honor the length with your change, provided the value is not longer than specified length.
Assert.AreEqual(SqlDbType.NVarChar, Driver.LastCommandParameters.First().SqlDbType); | ||
Assert.AreEqual(3, Driver.LastCommandParameters.First().Size); | ||
Assert.AreEqual(SqlDbType.VarChar, Driver.LastCommandParameters.Last().SqlDbType); | ||
Assert.AreEqual(3, Driver.LastCommandParameters.Last().Size); |
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.
For new tests, NUnit constraint model is favored other its classic model, see NUnit two models.
So it should be:
Assert.That(Driver.LastCommandParameters.First().SqlDbType, Is.EqualTo(SqlDbType.NVarChar));
Assert.That(Driver.LastCommandParameters.First().Size, Is.EqualTo(3));
Assert.That(Driver.LastCommandParameters.Last().SqlDbType, Is.EqualTo(SqlDbType.VarChar));
Assert.That(Driver.LastCommandParameters.Last().Size, Is.EqualTo(3));
Or maybe even:
Assert.That(
Driver.LastCommandParameters.First(),
Has.Property("SqlDbType").EqualTo(SqlDbType.NVarChar).And.Property("Size").EqualTo(3));
Assert.That(
Driver.LastCommandParameters.Last(),
Has.Property("SqlDbType").EqualTo(SqlDbType.VarChar).And.Property("Size").EqualTo(3));
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.
True. I reused my old tests from the previous PR. Will fix.
#else | ||
: ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider | ||
: ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider, IParameterAdjuster |
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.
Maybe move implemented interface declarations out of the #if
, in order to avoid duplicating them and only have in the #if
what changes.
#if NETFX
: DriverBase,
#else
: ReflectionBasedDriver,
#endif
IEmbeddedBatcherFactoryProvider, IParameterAdjuster
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.
Good idea.
I'll add some more tests (e.g using MappedAs, edge lengths etc.) |
[Obsolete("Use MsSql2000Dialect.MaxSizeForClob")] | ||
public const int MaxSizeForClob = 1073741823; // int.MaxValue / 2 | ||
// Since v5.1 | ||
// Since v5.1 |
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.
Strange spacing glitch here
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.
Huh? Strange indeed!
Hmmm...what do you say @fredericDelaporte? What behavior should we aim for when a value exceeds the max size. Going above e.g. MaxSizeForLengthLimitedString is mostly not a problem (but it may be for SQL Server 2000) |
About SQL Server 2000, well, its support has completely ended in 2013. So, I am for not caring about an edge case for this product. (Limited string parameters which value size happens to get above the the max limited string size.) So, when a value exceeds the max mapped size, I think setting the parameter size to the value size is a good choice. In fact I also question the validity of setting the size to Side note: the async tests need a regen. This is why they fail currently. |
2be8661
to
93640cc
Compare
I think I'm done with this one. Can rebase-squash if so desired. |
Could the tests be enabled for all dialects? |
Other dialect drivers do not set parameter sizes, so the tests would fail. Unless the size asserts are changed for being done only when the driver is the sql server one. |
At least ODBC driver does so. |
|
||
namespace NHibernate.AdoNet | ||
{ | ||
internal interface IParameterAdjuster |
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.
Why is it internal
? An external driver implementor may need it.
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.
It was a prototype, so I kept it from "the public". I wouldn't mind making it public.
95908fe
to
14b4930
Compare
Since it was conflicting with the latest merge on master, I have rebased it. And I have added a commit for switching the interface to public. |
Thanks! |
Fix for #1300. Replaces #480
Additional logic could be applied in the length calculation, to prevent query plan cache misses.