Esempio n. 1
0
 public override void Execute()
 {
     if (!this.IsPrepared)
     {
         base.Execute();
     }
     else
     {
         MySqlStream stream = new MySqlStream(base.Driver.Encoding);
         BitArray    array  = new BitArray(base.Parameters.Count);
         if (this.paramList != null)
         {
             for (int i = 0; i < this.paramList.Length; i++)
             {
                 MySqlParameter parameter = base.Parameters[this.paramList[i].ColumnName];
                 if ((parameter.Value == DBNull.Value) || (parameter.Value == null))
                 {
                     array[i] = true;
                 }
             }
         }
         byte[] buffer = new byte[(base.Parameters.Count + 7) / 8];
         if (buffer.Length > 0)
         {
             array.CopyTo(buffer, 0);
         }
         stream.WriteInteger((long)this.statementId, 4);
         stream.WriteByte(0);
         stream.WriteInteger(1L, 4);
         stream.Write(buffer);
         stream.WriteByte(1);
         if (this.paramList != null)
         {
             foreach (MySqlField field in this.paramList)
             {
                 MySqlParameter parameter2 = base.Parameters[field.ColumnName];
                 stream.WriteInteger((long)parameter2.GetPSType(), 2);
             }
             foreach (MySqlField field2 in this.paramList)
             {
                 int index = base.Parameters.IndexOf(field2.ColumnName);
                 if (index == -1)
                 {
                     throw new MySqlException("Parameter '" + field2.ColumnName + "' is not defined.");
                 }
                 MySqlParameter parameter3 = base.Parameters[index];
                 if ((parameter3.Value != DBNull.Value) && (parameter3.Value != null))
                 {
                     stream.Encoding = field2.Encoding;
                     parameter3.Serialize(stream, true);
                 }
             }
         }
         this.executionCount++;
         base.Driver.ExecuteStatement(stream.InternalBuffer.ToArray());
     }
 }
Esempio n. 2
0
 public override void Execute()
 {
     if (!this.IsPrepared)
     {
         base.Execute();
     }
     else
     {
         MySqlStream stream = new MySqlStream(base.Driver.Encoding);
         BitArray array = new BitArray(base.Parameters.Count);
         if (this.paramList != null)
         {
             for (int i = 0; i < this.paramList.Length; i++)
             {
                 MySqlParameter parameter = base.Parameters[this.paramList[i].ColumnName];
                 if ((parameter.Value == DBNull.Value) || (parameter.Value == null))
                 {
                     array[i] = true;
                 }
             }
         }
         byte[] buffer = new byte[(base.Parameters.Count + 7) / 8];
         if (buffer.Length > 0)
         {
             array.CopyTo(buffer, 0);
         }
         stream.WriteInteger((long) this.statementId, 4);
         stream.WriteByte(0);
         stream.WriteInteger(1L, 4);
         stream.Write(buffer);
         stream.WriteByte(1);
         if (this.paramList != null)
         {
             foreach (MySqlField field in this.paramList)
             {
                 MySqlParameter parameter2 = base.Parameters[field.ColumnName];
                 stream.WriteInteger((long) parameter2.GetPSType(), 2);
             }
             foreach (MySqlField field2 in this.paramList)
             {
                 int index = base.Parameters.IndexOf(field2.ColumnName);
                 if (index == -1)
                 {
                     throw new MySqlException("Parameter '" + field2.ColumnName + "' is not defined.");
                 }
                 MySqlParameter parameter3 = base.Parameters[index];
                 if ((parameter3.Value != DBNull.Value) && (parameter3.Value != null))
                 {
                     stream.Encoding = field2.Encoding;
                     parameter3.Serialize(stream, true);
                 }
             }
         }
         this.executionCount++;
         base.Driver.ExecuteStatement(stream.InternalBuffer.ToArray());
     }
 }
Esempio 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());
     }
 }
Esempio n. 4
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);
     }
 }
Esempio n. 5
0
        private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream)
        {
            for (int i = 0; i < length; i++)
            {
                byte num2 = bytes[i];
                switch (num2)
                {
                    case 0:
                        stream.WriteByte(0x5c);
                        stream.WriteByte(0x30);
                        break;

                    case 0x5c:
                    case 0x27:
                    case 0x22:
                        stream.WriteByte(0x5c);
                        stream.WriteByte(num2);
                        break;

                    default:
                        stream.WriteByte(num2);
                        break;
                }
            }
        }
Esempio n. 6
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);
     }
 }
Esempio n. 7
0
 void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object value, int length)
 {
     MySqlDateTime time;
     if (value is DateTime)
     {
         time = new MySqlDateTime(this.type, (DateTime) value);
     }
     else if (value is string)
     {
         time = new MySqlDateTime(this.type, DateTime.Parse((string) value, CultureInfo.CurrentCulture));
     }
     else
     {
         if (!(value is MySqlDateTime))
         {
             throw new MySqlException("Unable to serialize date/time value.");
         }
         time = (MySqlDateTime) value;
     }
     if (!binary)
     {
         this.SerializeText(stream, time);
     }
     else
     {
         if (this.type == MySqlDbType.Timestamp)
         {
             stream.WriteByte(11);
         }
         else
         {
             stream.WriteByte(7);
         }
         stream.WriteInteger((long) time.Year, 2);
         stream.WriteByte((byte) time.Month);
         stream.WriteByte((byte) time.Day);
         if (this.type == MySqlDbType.Date)
         {
             stream.WriteByte(0);
             stream.WriteByte(0);
             stream.WriteByte(0);
         }
         else
         {
             stream.WriteByte((byte) time.Hour);
             stream.WriteByte((byte) time.Minute);
             stream.WriteByte((byte) time.Second);
         }
         if (this.type == MySqlDbType.Timestamp)
         {
             stream.WriteInteger((long) time.Millisecond, 4);
         }
     }
 }