Uploaded image for project: 'NHibernate [Moved to GitHub]'
  1. NH-2893

NHibernate SQL Parameter on IBM.Data.DB2.iSeries provider

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 3.2.0.GA
    • Fix Version/s: 3.3.0.CR1
    • Component/s: Core
    • Labels:
      None
    • Sprint:

      Description

      I would like to report a bug on NHibernate v3.2.0.GA using IBM.Data.DB2.iSeries.dll (v7.1) reproduction of the error are as follows:

      Assuming we have a table USERS consisting of fields USER_ID, FULL_NAME, PASSWORD. NHibernate can easily retrieve all the records by issuing the statement:

      Session.CreateCriteria(Of objUsers).List(Of objUsers)();

      However, when trying to add a criteria :

      Session.CreateCriteria(Of objUsers).Add(Restrictions.InsensitiveLike("FULL_NAME", "john", MatchMode.Anywhere)).List(Of objUsers)();

      NHibernate generates an error:

      "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

      Browsing the source code of NHibernate led me to the routine that is causing the error:

      File Name: DriverBase.cs
      Function: RemoveUnusedCommandParameters()
      Code: cmd.Parameters
      .Cast<IDbDataParameter>()
      .Select(p => p.ParameterName)
      .Except(formatter.AssignedParameterNames)
      .ToList()
      .ForEach(ununsedParameterName =>

      { cmd.Parameters.RemoveAt(ununsedParameterName); }

      );

      The LINQ query that is been used for removing the unused parameters is removing the used command parameters. The result of
      formatter.AssignedParameterNames are "?" for each parameter while the parameter names for cmd.Parameters are "p0, p1" thus
      removing all the parameters used or unused for the query. As a temporary fix, I just commented-out the code above and NHibernate
      can now successfully retrieve the records given a specified criteria. I think the problem is due to the SQL syntax of DB2 wherein all
      parameters are represented with a question mark sign "?". I will also try to analyze the source code to find a solution to this bug.

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                daprogrammer percival evangelio
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Who's Looking?