private Serialize ( |
||
packet | ||
binary | bool | |
settings | ||
Résultat | void |
public override void Execute() { if (!this.IsPrepared) { base.Execute(); return; } this.packet.Position = this.dataPosition; for (int i = 0; i < this.parametersToSend.Count; i++) { MySqlParameter mySqlParameter = this.parametersToSend[i]; this.nullMap[i] = (mySqlParameter.Value == DBNull.Value || mySqlParameter.Value == null || mySqlParameter.Direction == ParameterDirection.Output); if (!this.nullMap[i]) { this.packet.Encoding = mySqlParameter.Encoding; mySqlParameter.Serialize(this.packet, true, base.Connection.Settings); } } if (this.nullMap != null) { this.nullMap.CopyTo(this.packet.Buffer, this.nullMapPosition); } this.executionCount++; base.Driver.ExecuteStatement(this.packet); }
/// <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, int parameterIndex) { MySqlParameter parameter = null; if (!parameters.containsUnnamedParameters) parameter = parameters.GetParameterFlexible(parmName, false); else { if (parameterIndex <= parameters.Count) parameter = parameters[parameterIndex]; else throw new MySqlException(Resources.ParameterIndexNotFound); } 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("@", StringComparison.Ordinal) && ShouldIgnoreMissingParameter(parmName)) return false; throw new MySqlException( String.Format(Resources.ParameterMustBeDefined, parmName)); } parameter.Serialize(packet, false, Connection.Settings); return true; }
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) { byte[] tempByteArray = new byte[(_nullMap.Length + 7) >> 3]; _nullMap.CopyTo(tempByteArray, 0); Array.Copy(tempByteArray, 0, _packet.Buffer, _nullMapPosition, tempByteArray.Length); } ExecutionCount++; Driver.ExecuteStatement(_packet); }
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())); }
private bool SerializeParameter(PacketWriter writer, string parmName) { MySqlParameter parameter = this.GetParameter(this.parameters, parmName); if (parameter != null) { parameter.Serialize(writer, false); return(true); } if (this.Connection.Settings.UseOldSyntax) { return(false); } throw new MySqlException(string.Format(Resources.ParameterMustBeDefined, new object[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, MySqlStream stream, 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(Resources.ParameterMustBeDefined, parmName)); } parameter.Serialize(stream, false); return true; }
/// <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("@", StringComparison.Ordinal) && ShouldIgnoreMissingParameter(parmName)) { return(false); } throw new MySqlException( String.Format(Resources.ParameterMustBeDefined, parmName)); } parameter.Serialize(packet, false, Connection.Settings); return(true); }
/// <summary> /// Serializes the given parameter to the given memory stream /// </summary> /// <param name="writer">PacketWriter to stream parameter data to</param> /// <param name="parmName">Name of the parameter to serialize</param> /// <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(PacketWriter writer, string parmName) { int index = parameters.IndexOf(parmName); if (index == -1) { // if we are using old syntax, we can't throw exceptions for parameters // not defined. if (connection.Settings.UseOldSyntax) { return(false); } throw new MySqlException("Parameter '" + parmName + "' must be defined"); } MySqlParameter parameter = parameters[index]; parameter.Serialize(writer, false); return(true); }
/// <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, MySqlStream stream, string parmName) { MySqlParameter parameter = GetParameter(parameters, parmName); if (parameter == null) { // if we are using old syntax, we can't throw exceptions for parameters // not defined. if (Connection.Settings.UseOldSyntax) { return(false); } throw new MySqlException( String.Format(Resources.ParameterMustBeDefined, parmName)); } parameter.Serialize(stream, false); return(true); }
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()); }
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())); }