void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length) { string v = val.ToString(); if (length > 0) { length = Math.Min(length, v.Length); v = v.Substring(0, length); } if (binary) packet.WriteLenString(v); else packet.WriteStringNoNull("'" + MySqlHelper.EscapeString(v) + "'"); }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length) { Guid guid = Guid.Empty; string valAsString = val as string; byte[] valAsByte = val as byte[]; if (val is Guid) guid = (Guid)val; else { try { if (valAsString != null) guid = new Guid(valAsString); else if (valAsByte != null) guid = new Guid(valAsByte); } catch (Exception ex) { throw new MySqlException(Resources.DataNotInSupportedFormat, ex); } } if (OldGuids) WriteOldGuid(packet, guid, binary); else { guid.ToString("D"); if (binary) packet.WriteLenString(guid.ToString("D")); else packet.WriteStringNoNull("'" + MySqlHelper.EscapeString(guid.ToString("D")) + "'"); } }
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length) { decimal v = (val is decimal) ? (decimal)val : Convert.ToDecimal(val); string valStr = v.ToString(CultureInfo.InvariantCulture); if (binary) packet.WriteLenString(valStr); else packet.WriteStringNoNull(valStr); }