internal void SetConnectAttrs() { // Sets connect attributes if ((connectionFlags & ClientFlags.CONNECT_ATTRS) != 0) { string connectAttrs = string.Empty; MySqlConnectAttrs attrs = new MySqlConnectAttrs(); foreach (PropertyInfo property in attrs.GetType().GetProperties()) { string name = property.Name; #if NETSTANDARD1_6 object[] customAttrs = property.GetCustomAttributes(typeof(DisplayNameAttribute), false).ToArray(); #else object[] customAttrs = property.GetCustomAttributes(typeof(DisplayNameAttribute), false).ToArray(); #endif if (customAttrs.Length > 0) { name = (customAttrs[0] as DisplayNameAttribute).DisplayName; } string value = (string)property.GetValue(attrs, null); connectAttrs += string.Format("{0}{1}", (char)name.Length, name); connectAttrs += string.Format("{0}{1}", (char)value.Length, value); } packet.WriteLenString(connectAttrs); } }
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) { 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); }
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")) + "'"); } }