Beispiel #1
0
        public override void Execute()
        {
            // if we are not prepared, then call down to our base
            if (!IsPrepared)
            {
                base.Execute();
                return;
            }

            //TODO: support long data here
            // create our null bitmap

            // we check this because Mono doesn't ignore the case where nullMapBytes
            // is zero length.
            //            if (nullMapBytes.Length > 0)
            //          {
            //            byte[] bits = packet.Buffer;
            //          nullMap.CopyTo(bits,
            //        nullMap.CopyTo(nullMapBytes, 0);

            // start constructing our packet
            //            if (Parameters.Count > 0)
            //              nullMap.CopyTo(packet.Buffer, nullMapPosition);
            //if (parameters != null && parameters.Count > 0)
            //else
            //	packet.WriteByte( 0 );
            //TODO:  only send rebound if parms change

            // now write out all non-null values
            packet.Position = dataPosition;
            for (int i = 0; i < parametersToSend.Count; i++)
            {
                MySqlParameter p = parametersToSend[i];
                nullMap[i] = (p.Value == DBNull.Value || p.Value == null) ||
                             p.Direction == ParameterDirection.Output;
                if (nullMap[i])
                {
                    continue;
                }
                packet.Encoding = p.Encoding;
                p.Serialize(packet, true, Connection.Settings);
            }
            if (nullMap != null)
            {
                ToByteArray(nullMap, packet.Buffer, nullMapPosition);
            }

            executionCount++;

            Driver.ExecuteStatement(packet);
        }
Beispiel #2
0
        /// <summary>
        /// Serializes the given parameter to the given memory stream
        /// </summary>
        /// <remarks>
        /// <para>This method is called by PrepareSqlBuffers to convert the given
        /// parameter to bytes and write those bytes to the given memory stream.
        /// </para>
        /// </remarks>
        /// <returns>True if the parameter was successfully serialized, false otherwise.</returns>
        private bool SerializeParameter(MySqlParameterCollection parameters,
                                        MySqlPacket packet, string parmName)
        {
            MySqlParameter parameter = parameters.GetParameterFlexible(parmName, false);

            if (parameter == null)
            {
                // if we are allowing user variables and the parameter name starts with @
                // then we can't throw an exception
                if (parmName.StartsWith("@") && ShouldIgnoreMissingParameter(parmName))
                {
                    return(false);
                }
                throw new MySqlException(
                          String.Format(ResourceStrings.ParameterMustBeDefined, parmName));
            }
            parameter.Serialize(packet, false, Connection.Settings);
            return(true);
        }