GetPSType() private method

private GetPSType ( ) : int
return int
        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;
        }
        public CommandResult Execute(MySqlParameterCollection parameters)
        {
            PacketWriter packetWriter = new PacketWriter();

            packetWriter.Driver = (NativeDriver)this.driver;
            BitArray bitArray = new BitArray(parameters.Count);

            for (int i = 0; i < this.paramList.Length; i++)
            {
                MySqlParameter mySqlParameter = parameters[this.paramList[i].ColumnName];
                if (mySqlParameter.Value == DBNull.Value || mySqlParameter.Value == null)
                {
                    bitArray[i] = true;
                }
            }
            byte[] array = new byte[(parameters.Count + 7) / 8];
            if (array.Length > 0)
            {
                bitArray.CopyTo(array, 0);
            }
            packetWriter.WriteInteger((long)this.StatementId, 4);
            packetWriter.WriteByte(0);
            packetWriter.WriteInteger(1L, 4);
            packetWriter.Write(array);
            packetWriter.WriteByte(1);
            MySqlField[] array2 = this.paramList;
            for (int j = 0; j < array2.Length; j++)
            {
                MySqlField     mySqlField      = array2[j];
                MySqlParameter mySqlParameter2 = parameters[mySqlField.ColumnName];
                packetWriter.WriteInteger((long)mySqlParameter2.GetPSType(), 2);
            }
            array2 = this.paramList;
            for (int j = 0; j < array2.Length; j++)
            {
                MySqlField mySqlField2 = array2[j];
                int        num         = parameters.IndexOf(mySqlField2.ColumnName);
                if (num == -1)
                {
                    throw new MySqlException("Parameter '" + mySqlField2.ColumnName + "' is not defined.");
                }
                MySqlParameter mySqlParameter3 = parameters[num];
                if (mySqlParameter3.Value != DBNull.Value && mySqlParameter3.Value != null)
                {
                    packetWriter.Encoding = mySqlField2.Encoding;
                    mySqlParameter3.Serialize(packetWriter, true);
                }
            }
            this.executionCount++;
            return(this.driver.ExecuteStatement(((MemoryStream)packetWriter.Stream).ToArray()));
        }
        public override void Execute()
        {
            // if we are not prepared, then call down to our base
            if (!IsPrepared)
            {
                base.Execute();
                return;
            }

            MySqlStream stream = new MySqlStream(Driver.Encoding);

            //TODO: support long data here
            // create our null bitmap
            BitArray nullMap = new BitArray(Parameters.Count);

            // now we run through the parameters that PREPARE sent back and use
            // those names to index into the parameters the user gave us.
            // if the user set that parameter to NULL, then we set the null map
            // accordingly
            if (paramList != null)
            {
                for (int x = 0; x < paramList.Length; x++)
                {
                    MySqlParameter p = Parameters[paramList[x].ColumnName];
                    if (p.Value == DBNull.Value || p.Value == null)
                    {
                        nullMap[x] = true;
                    }
                }
            }
            byte[] nullMapBytes = new byte[(Parameters.Count + 7) / 8];

            // we check this because Mono doesn't ignore the case where nullMapBytes
            // is zero length.
            if (nullMapBytes.Length > 0)
            {
                nullMap.CopyTo(nullMapBytes, 0);
            }

            // start constructing our packet
            stream.WriteInteger(statementId, 4);
            stream.WriteByte(0);       // flags; always 0 for 4.1
            stream.WriteInteger(1, 4); // interation count; 1 for 4.1
            stream.Write(nullMapBytes);
            //if (parameters != null && parameters.Count > 0)
            stream.WriteByte(1); // rebound flag
            //else
            //	packet.WriteByte( 0 );
            //TODO:  only send rebound if parms change

            // write out the parameter types
            if (paramList != null)
            {
                foreach (MySqlField param in paramList)
                {
                    MySqlParameter parm = Parameters[param.ColumnName];
                    stream.WriteInteger(parm.GetPSType(), 2);
                }

                // now write out all non-null values
                foreach (MySqlField param in paramList)
                {
                    int index = Parameters.IndexOf(param.ColumnName);
                    if (index == -1)
                    {
                        throw new MySqlException("Parameter '" + param.ColumnName +
                                                 "' is not defined.");
                    }
                    MySqlParameter parm = Parameters[index];
                    if (parm.Value == DBNull.Value || parm.Value == null)
                    {
                        continue;
                    }

                    stream.Encoding = param.Encoding;
                    parm.Serialize(stream, true);
                }
            }

            executionCount++;

            Driver.ExecuteStatement(stream.InternalBuffer.ToArray());
        }
Beispiel #4
0
        public CommandResult Execute(MySqlParameterCollection parameters)
        {
            PacketWriter packet = new PacketWriter();

            packet.Driver = (NativeDriver)driver;

            //TODO: support long data here
            // create our null bitmap
            BitArray nullMap = new BitArray(parameters.Count);               //metaData.Length );

            for (int x = 0; x < parameters.Count; x++)
            {
                if (parameters[x].Value == DBNull.Value ||
                    parameters[x].Value == null)
                {
                    nullMap[x] = true;
                }
            }
            byte[] nullMapBytes = new byte[(parameters.Count + 7) / 8];
            nullMap.CopyTo(nullMapBytes, 0);

            // start constructing our packet
            packet.WriteInteger(StatementId, 4);
            packet.WriteByte(0);                        // flags; always 0 for 4.1
            packet.WriteInteger(1, 4);                  // interation count; 1 for 4.1
            packet.Write(nullMapBytes);
            //if (parameters != null && parameters.Count > 0)
            packet.WriteByte(1);                                        // rebound flag
            //else
            //	packet.WriteByte( 0 );
            //TODO:  only send rebound if parms change

            // write out the parameter types
            foreach (MySqlField param in paramList)
            {
                MySqlParameter parm = parameters[param.ColumnName];
                packet.WriteInteger((long)parm.GetPSType(), 2);
            }

            // now write out all non-null values
            foreach (MySqlField param in paramList)
            {
                int index = parameters.IndexOf(param.ColumnName);
                if (index == -1)
                {
                    throw new MySqlException("Parameter '" + param.ColumnName +
                                             "' is not defined.");
                }
                MySqlParameter parm = parameters[index];
                if (parm.Value == DBNull.Value || parm.Value == null)
                {
                    continue;
                }

                packet.Encoding = param.Encoding;
                parm.Serialize(packet, true);
            }

            executionCount++;
            // send the data packet and return the CommandResult
            return(driver.ExecuteStatement(((System.IO.MemoryStream)packet.Stream).ToArray()));
        }