本文整理汇总了C#中MySql.Data.MySqlClient.MySqlPacket.WriteLength方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlPacket.WriteLength方法的具体用法?C# MySqlPacket.WriteLength怎么用?C# MySqlPacket.WriteLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlPacket
的用法示例。
在下文中一共展示了MySqlPacket.WriteLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MySqlException
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
byte[] buffToWrite = (val as byte[]);
if (buffToWrite == null)
{
char[] valAsChar = (val as Char[]);
if (valAsChar != null)
buffToWrite = packet.Encoding.GetBytes(valAsChar);
else
{
string s = val.ToString();
if (length == 0)
length = s.Length;
else
s = s.Substring(0, length);
buffToWrite = packet.Encoding.GetBytes(s);
}
}
// we assume zero length means write all of the value
if (length == 0)
length = buffToWrite.Length;
if (buffToWrite == null)
throw new MySqlException("Only byte arrays and strings can be serialized by MySqlBinary");
if (binary)
{
packet.WriteLength(length);
packet.Write(buffToWrite, 0, length);
}
else
{
if (packet.Version.isAtLeast(4, 1, 0))
packet.WriteStringNoNull("_binary ");
packet.WriteByte((byte)'\'');
EscapeByteArray(buffToWrite, length, packet);
packet.WriteByte((byte)'\'');
}
}
示例2: WriteOldGuid
private void WriteOldGuid(MySqlPacket packet, Guid guid, bool binary)
{
byte[] bytes = guid.ToByteArray();
if (binary)
{
packet.WriteLength(bytes.Length);
packet.Write(bytes);
}
else
{
packet.WriteStringNoNull("_binary ");
packet.WriteByte((byte)'\'');
EscapeByteArray(bytes, bytes.Length, packet);
packet.WriteByte((byte)'\'');
}
}