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());
     }
 }
Exemple #2
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);
			}
		}
Exemple #3
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);
				}
			}
		}