Exemplo n.º 1
0
        protected virtual void BindParameters()
        {
            MySqlParameterCollection parameters = this.command.Parameters;
            int num = 0;

            do
            {
                this.InternalBindParameters(this.ResolvedCommandText, parameters, null);
                if (this.command.Batch != null)
                {
                    while (num < this.command.Batch.Count)
                    {
                        MySqlCommand command = this.command.Batch[num++];
                        MySqlStream  stream  = (MySqlStream)this.buffers[this.buffers.Count - 1];
                        long         num2    = command.EstimatedSize();
                        if ((stream.InternalBuffer.Length + num2) > this.Connection.driver.MaxPacketSize)
                        {
                            parameters = command.Parameters;
                            break;
                        }
                        this.buffers.RemoveAt(this.buffers.Count - 1);
                        long   length = stream.InternalBuffer.Length;
                        string batchableCommandText = command.BatchableCommandText;
                        if (batchableCommandText.StartsWith("("))
                        {
                            stream.WriteStringNoNull(", ");
                        }
                        else
                        {
                            stream.WriteStringNoNull("; ");
                        }
                        this.InternalBindParameters(batchableCommandText, command.Parameters, stream);
                        if (stream.InternalBuffer.Length > this.Connection.driver.MaxPacketSize)
                        {
                            stream.InternalBuffer.SetLength(length);
                            parameters = command.Parameters;
                            break;
                        }
                    }
                }
                else
                {
                    return;
                }
            }while (num != this.command.Batch.Count);
        }
Exemplo n.º 2
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     ulong num = Convert.ToUInt64(val);
     if (binary)
     {
         stream.Write(BitConverter.GetBytes(num));
     }
     else
     {
         stream.WriteStringNoNull(num.ToString());
     }
 }
Exemplo n.º 3
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     byte num = ((IConvertible) val).ToByte(null);
     if (binary)
     {
         stream.WriteByte(num);
     }
     else
     {
         stream.WriteStringNoNull(num.ToString());
     }
 }
Exemplo n.º 4
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     float num = Convert.ToSingle(val);
     if (binary)
     {
         stream.Write(BitConverter.GetBytes(num));
     }
     else
     {
         stream.WriteStringNoNull(num.ToString("R", CultureInfo.InvariantCulture));
     }
 }
Exemplo n.º 5
0
        internal void Serialize(MySqlStream stream, bool binary)
        {
            IMySqlValue iMySqlValue = MySqlField.GetIMySqlValue(this.mySqlDbType);

            if (!binary && ((this.paramValue == null) || (this.paramValue == DBNull.Value)))
            {
                stream.WriteStringNoNull("NULL");
            }
            else
            {
                iMySqlValue.WriteValue(stream, binary, this.paramValue, this.size);
            }
        }
Exemplo n.º 6
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     string s = val.ToString();
     if (length > 0)
     {
         length = Math.Min(length, s.Length);
         s = s.Substring(0, length);
     }
     if (binary)
     {
         stream.WriteLenString(s);
     }
     else
     {
         stream.WriteStringNoNull("'" + MySqlHelper.EscapeString(s) + "'");
     }
 }
Exemplo n.º 7
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     if (!(val is TimeSpan))
     {
         throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
     }
     TimeSpan span = (TimeSpan) val;
     bool flag = span.TotalMilliseconds < 0.0;
     span = span.Duration();
     if (binary)
     {
         stream.WriteByte(8);
         stream.WriteByte(flag ? ((byte) 1) : ((byte) 0));
         stream.WriteInteger((long) span.Days, 4);
         stream.WriteByte((byte) span.Hours);
         stream.WriteByte((byte) span.Minutes);
         stream.WriteByte((byte) span.Seconds);
     }
     else
     {
         string v = string.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'", new object[] { flag ? "-" : "", span.Days, span.Hours, span.Minutes, span.Seconds, span.Milliseconds });
         stream.WriteStringNoNull(v);
     }
 }
Exemplo n.º 8
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     string s = Convert.ToDecimal(val).ToString(CultureInfo.InvariantCulture);
     if (binary)
     {
         stream.WriteLenString(s);
     }
     else
     {
         stream.WriteStringNoNull(s);
     }
 }
Exemplo n.º 9
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
 {
     byte[] bytes = null;
     if (val is byte[])
     {
         bytes = (byte[]) val;
     }
     else if (val is char[])
     {
         bytes = stream.Encoding.GetBytes(val as char[]);
     }
     else
     {
         string s = val.ToString();
         if (length == 0)
         {
             length = s.Length;
         }
         else
         {
             s = s.Substring(0, length);
         }
         bytes = stream.Encoding.GetBytes(s);
     }
     if (length == 0)
     {
         length = bytes.Length;
     }
     if (bytes == null)
     {
         throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
     }
     if (binary)
     {
         stream.WriteLength((long) length);
         stream.Write(bytes, 0, length);
     }
     else
     {
         if (stream.Version.isAtLeast(4, 1, 0))
         {
             stream.WriteStringNoNull("_binary ");
         }
         stream.WriteByte(0x27);
         this.EscapeByteArray(bytes, length, stream);
         stream.WriteByte(0x27);
     }
 }
Exemplo n.º 10
0
 private void SerializeText(MySqlStream stream, MySqlDateTime value)
 {
     string str = string.Empty;
     if ((this.type == MySqlDbType.Timestamp) && !stream.Version.isAtLeast(4, 1, 0))
     {
         str = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}", new object[] { value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second });
     }
     else
     {
         str = string.Format("{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day);
         if (this.type != MySqlDbType.Date)
         {
             str = string.Format("{0}  {1:00}:{2:00}:{3:00}", new object[] { str, value.Hour, value.Minute, value.Second });
         }
     }
     stream.WriteStringNoNull("'" + str + "'");
 }