Too late.
Team have decided that the implemented will be the default to speed up MsSQL
server.

On Fri, Sep 24, 2010 at 3:45 AM, Maxim Filimonov <[email protected]>wrote:

> Figured out the problem.
> It's impossible to achieve such behavior by only inheriting from
> SqlClientDriver.
> The class already contains call to set parameter size
> public override IDbCommand GenerateCommand(CommandType type, SqlString
> sqlString, SqlType[] parameterTypes)
>        {
>            IDbCommand command = base.GenerateCommand(type, sqlString,
> parameterTypes);
>            //if (IsPrepareSqlEnabled)
>            {
>                SetParameterSizes(command.Parameters, parameterTypes);
>            }
>            return command;
>        }
> So when in inherited class I call base.GenerateCommand() parameter
> sizes is set automatically.
> The only way I found is to revert to your first suggestion and copy/
> paste SqlClientDriver code from NH sources and uncomment the line.
> Just wondering why this line is commented? Would it be possible to
> uncomment it and make default behavior to not throw exception but to
> allow users to control this behavior with prepare_sql param?
> Anyway, thanks for your help Fabio.
> Yours sincerely,
> Maxim Filimonov
>
> On 24 сен, 10:05, Maxim Filimonov <[email protected]> wrote:
> > Dear Fabio,
> > Thanks for detailed instruction but it doesn't work at least in my
> > setup (NH3.0 Alpha 2) base.GenerateCommand already returns parameters
> > with size's set to values from mapping. I'll continue to dig into NH
> > sources.
> > Yours sincerely,
> > Maxim Filimonov
> >
> > On 23 сен, 21:31, Fabio Maulo <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Inherit from SqlClientDriver and do this
> > > public override IDbCommand GenerateCommand(CommandType type, SqlString
> > > sqlString, SqlType[] parameterTypes)
> > > {
> > > IDbCommand command = base.GenerateCommand(type, sqlString,
> parameterTypes);
> > > if (IsPrepareSqlEnabled)
> > > {
> > > SetParameterSizes(command.Parameters, parameterTypes);
> >
> > > }
> > > return command;
> > > }
> >
> > > Then you will have a way to enable/disable the feature using the
> > > "prepare_sql" property of session-factory config.
> >
> > > On Thu, Sep 23, 2010 at 12:15 PM, Maxim Filimonov <[email protected]
> >wrote:
> >
> > > > Dear Fabio,
> > > > Thanks for the quick response.
> > > > I'll try your suggestion, thx.
> >
> > > > On 23 сен, 19:05, Fabio Maulo <[email protected]> wrote:
> > > > > No, it is not a bug istead it is a specific request to make happy
> > > > MsSqlServer.
> > > > > If you want the old behavior you have to copy&paste the
> SqlClientDrive
> > > > > and disable the actual behavior, the you have to specify your
> > > > > implementation in the sessio-factory configuration.
> >
> > > > > --
> > > > > Fabio Maulo
> >
> > > > > El 23/09/2010, a las 11:10, Maxim Filimonov <[email protected]>
> > > > escribió:
> >
> > > > > > Dear Everybody,
> > > > > > I've played with Nhibernate 3 Alpha 2 for a while and recently
> found a
> > > > > > bit confusing behaviour at least from standpoint of compatability
> with
> > > > > > version 2.1.2.
> > > > > > A problem occurs when I try to insert(didn't try to update but I
> > > > > > suppose it can have the same problem) string value to column with
> > > > > > limited length.
> > > > > > In 2.1.2 when such insert occurs my db engine(MSSQL SERVER 2008)
> > > > > > throws an exception "String or binary data would be truncated."
> which
> > > > > > gives me ability to rollback transaction at least if business
> layer
> > > > > > didn't check length of a field. With the version 3.0 Alpha 2 db
> engine
> > > > > > doesn't throw any exception on such insert because value is
> truncated
> > > > > > automagically by nhibernate. Generated SQL:
> > > > > > 2.1.2:
> > > > > > exec sp_executesql N'INSERT INTO Customers (FirstName) VALUES
> (@p0);
> > > > > > select SCOPE_IDENTITY()',N'@p0nvarchar(16)',@p0=N'MoreThan3Symbols'
> > > > > > 3.0:
> > > > > > exec sp_executesql N'INSERT INTO Customers (FirstName) VALUES
> (@p0);
> > > > > > select SCOPE_IDENTITY()',N'@p0 nvarchar(3)',@p0=N'Mor'
> >
> > > > > > My mapping:
> > > > > > <class name="TruncateBug.Customer,TruncateBug" table="Customers">
> > > > > >        <id name="CustomerId" column="CustomerId">
> > > > > >            <generator class="native"/>
> > > > > >        </id>
> > > > > >        <property name="FirstName" column="FirstName" length="3"/>
> > > > > >    </class>
> > > > > > And the code that doesn't produce exception anymore:
> > > > > > var invalidCustomer = new Customer() { FirstName =
> > > > > > "MoreThan3Symbols" };
> > > > > > int id = (int)session.Save(invalidCustomer);
> >
> > > > > > And yes session will contain Customer  object with full length
> > > > > > FirstName which could lead to a lot of misunderstanding in
> further
> > > > > > usage of the Customer object in scope of this session.
> >
> > > > > > Maybe it's not a bug but a feature but then I hope there is a way
> to
> > > > > > configure nhiberate to throw exception as previously and to not
> try to
> > > > > > create magic for me.
> >
> > > > > > Thanks in advance,
> > > > > > Yours sincerely,
> > > > > > Maxim Filimonov
> >
> > > > > > --
> > > > > > You received this message because you are subscribed to the
> Google
> > > > Groups "nhusers" group.
> > > > > > To post to this group, send email to [email protected].
> > > > > > To unsubscribe from this group, send email to
> > > > [email protected]<nhusers%[email protected]>
> <nhusers%[email protected]<nhusers%[email protected]>
> >
> > > > .
> > > > > > For more options, visit this group athttp://
> > > > groups.google.com/group/nhusers?hl=en.
> >
> > > > --
> > > > You received this message because you are subscribed to the Google
> Groups
> > > > "nhusers" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<nhusers%[email protected]>
> <nhusers%[email protected]<nhusers%[email protected]>
> >
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/nhusers?hl=en.
> >
> > > --
> > > Fabio Maulo
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>


-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to