MySql.Data.MySqlClient.MySqlPacket.WriteInteger C# (CSharp) Méthode

WriteInteger() public méthode

WriteInteger
public WriteInteger ( long v, int numbytes ) : void
v long
numbytes int
Résultat void
    public void WriteInteger(long v, int numbytes)
    {
      long val = v;

      Debug.Assert(numbytes > 0 && numbytes < 9);

      for (int x = 0; x < numbytes; x++)
      {
        tempBuffer[x] = (byte)(val & 0xff);
        val >>= 8;
      }
      Write(tempBuffer, 0, numbytes);
    }

Usage Example

        public virtual void Prepare()
        {
            // strip out names from parameter markers
            string        text;
            List <string> parameter_names = PrepareCommandText(out text);

            // ask our connection to send the prepare command
            MySqlField[] paramList = null;
            statementId = Driver.PrepareStatement(text, ref paramList);

            // now we need to assign our field names since we stripped them out
            // for the prepare
            for (int i = 0; i < parameter_names.Count; i++)
            {
                //paramList[i].ColumnName = (string) parameter_names[i];
                string         parameterName = (string)parameter_names[i];
                MySqlParameter p             = Parameters.GetParameterFlexible(parameterName, false);
                if (p == null)
                {
                    throw new InvalidOperationException(
                              String.Format(Resources.ParameterNotFoundDuringPrepare, parameterName));
                }
                p.Encoding = paramList[i].Encoding;
                parametersToSend.Add(p);
            }

            // now prepare our null map
            int numNullBytes = 0;

            if (paramList != null && paramList.Length > 0)
            {
#if RT || NETSTANDARD1_5
                nullMap = new RtBitArray(paramList.Length);
#else
                nullMap = new BitArray(paramList.Length);
#endif
                numNullBytes = (nullMap.Count + 7) / 8;
            }

            packet = new MySqlPacket(Driver.Encoding);

            // write out some values that do not change run to run
            packet.WriteByte(0);
            packet.WriteInteger(statementId, 4);
            packet.WriteByte((byte)0);       // flags; always 0 for 4.1
            packet.WriteInteger(1, 4);       // interation count; 1 for 4.1
            nullMapPosition  = packet.Position;
            packet.Position += numNullBytes; // leave room for our null map
            packet.WriteByte(1);             // rebound flag
            // write out the parameter types
            foreach (MySqlParameter p in parametersToSend)
            {
                packet.WriteInteger(p.GetPSType(), 2);
            }
            dataPosition = packet.Position;
        }
All Usage Examples Of MySql.Data.MySqlClient.MySqlPacket::WriteInteger