MapParameter() private method

Called by SqliteParameterCollection, this function determines if the specified parameter name belongs to this statement, and if so, keeps a reference to the parameter so it can be bound later.
private MapParameter ( string s, SqliteParameter p ) : bool
s string The parameter name to map
p SqliteParameter The parameter to assign it
return bool
Esempio n. 1
0
        /// <summary>
        /// This function attempts to map all parameters in the collection to all statements in a Command.
        /// Since named parameters may span multiple statements, this function makes sure all statements are bound
        /// to the same named parameter.  Unnamed parameters are bound in sequence.
        /// </summary>
        internal void MapParameters(SqliteStatement activeStatement)
        {
            if (_unboundFlag == false || _parameterList.Count == 0 || _command._statementList == null)
            {
                return;
            }

            int             nUnnamed = 0;
            string          s;
            int             n;
            int             y = -1;
            SqliteStatement stmt;

            foreach (SqliteParameter p in _parameterList)
            {
                y++;
                s = p.ParameterName;
                if (s == null)
                {
                    s = String.Format(CultureInfo.InvariantCulture, ";{0}", nUnnamed);
                    nUnnamed++;
                }

                int  x;
                bool isMapped = false;

                if (activeStatement == null)
                {
                    x = _command._statementList.Count;
                }
                else
                {
                    x = 1;
                }

                stmt = activeStatement;
                for (n = 0; n < x; n++)
                {
                    isMapped = false;
                    if (stmt == null)
                    {
                        stmt = _command._statementList[n];
                    }
                    if (stmt._paramNames != null)
                    {
                        if (stmt.MapParameter(s, p) == true)
                        {
                            isMapped = true;
                        }
                    }
                    stmt = null;
                }

                // If the parameter has a name, but the SQL statement uses unnamed references, this can happen -- attempt to map
                // the parameter by its index in the collection
                if (isMapped == false)
                {
                    s = String.Format(CultureInfo.InvariantCulture, ";{0}", y);

                    stmt = activeStatement;
                    for (n = 0; n < x; n++)
                    {
                        if (stmt == null)
                        {
                            stmt = _command._statementList[n];
                        }
                        if (stmt._paramNames != null)
                        {
                            if (stmt.MapParameter(s, p) == true)
                            {
                                isMapped = true;
                            }
                        }
                        stmt = null;
                    }
                }
            }
            if (activeStatement == null)
            {
                _unboundFlag = false;
            }
        }
    /// <summary>
    /// This function attempts to map all parameters in the collection to all statements in a Command.
    /// Since named parameters may span multiple statements, this function makes sure all statements are bound
    /// to the same named parameter.  Unnamed parameters are bound in sequence.
    /// </summary>
    internal void MapParameters(SqliteStatement activeStatement)
    {
      if (_unboundFlag == false || _parameterList.Count == 0 || _command._statementList == null) return;

      int nUnnamed = 0;
      string s;
      int n;
      int y = -1;
      SqliteStatement stmt;

      foreach(SqliteParameter p in _parameterList)
      {
        y ++;
        s = p.ParameterName;
        if (s == null)
        {
          s = String.Format(CultureInfo.InvariantCulture, ";{0}", nUnnamed);
          nUnnamed++;
        }

        int x;
        bool isMapped = false;

        if (activeStatement == null)
          x = _command._statementList.Count;
        else
          x = 1;

        stmt = activeStatement;
        for (n = 0; n < x; n++)
        {
          isMapped = false;
          if (stmt == null) stmt = _command._statementList[n];
          if (stmt._paramNames != null)
          {
            if (stmt.MapParameter(s, p) == true)
              isMapped = true;
          }
          stmt = null;
        }

        // If the parameter has a name, but the SQL statement uses unnamed references, this can happen -- attempt to map
        // the parameter by its index in the collection
        if (isMapped == false)
        {
          s = String.Format(CultureInfo.InvariantCulture, ";{0}", y);

          stmt = activeStatement;
          for (n = 0; n < x; n++)
          {
            if (stmt == null) stmt = _command._statementList[n];
            if (stmt._paramNames != null)
            {
              if (stmt.MapParameter(s, p) == true)
                isMapped = true;
            }
            stmt = null;
          }
        }
      }
      if (activeStatement == null) _unboundFlag = false;
    }