本文整理汇总了C#中MySql.Data.MySqlClient.MySqlPacket.Write方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlPacket.Write方法的具体用法?C# MySqlPacket.Write怎么用?C# MySqlPacket.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlPacket
的用法示例。
在下文中一共展示了MySqlPacket.Write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
double v = (val is double) ? (double)val : Convert.ToDouble(val);
if (binary)
packet.Write(BitConverter.GetBytes(v));
else
packet.WriteStringNoNull(v.ToString("R", CultureInfo.InvariantCulture));
}
示例2: 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)'\'');
}
}
示例3: Open
public void Open()
{
// connect to one of our specified hosts
try
{
#if !CF
if (Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory)
{
SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName);
str.Open(Settings.ConnectionTimeout);
baseStream = str;
}
else
{
#endif
string pipeName = Settings.PipeName;
if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe)
pipeName = null;
StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName,
Settings.Keepalive, this.Version);
#if !CF
if (Settings.IncludeSecurityAsserts)
MySqlSecurityPermission.CreatePermissionSet(false).Assert();
#endif
baseStream = sc.GetStream(Settings.ConnectionTimeout);
#if !CF
}
#endif
}
catch (System.Security.SecurityException)
{
throw;
}
catch (Exception ex)
{
throw new MySqlException(Resources.UnableToConnectToHost,
(int)MySqlErrorCode.UnableToConnectToHost, ex);
}
if (baseStream == null)
throw new MySqlException(Resources.UnableToConnectToHost,
(int)MySqlErrorCode.UnableToConnectToHost);
int maxSinglePacket = 255 * 255 * 255;
stream = new MySqlStream(baseStream, Encoding, false);
stream.ResetTimeout((int)Settings.ConnectionTimeout * 1000);
// read off the welcome packet and parse out it's values
packet = stream.ReadPacket();
int protocol = packet.ReadByte();
string versionString = packet.ReadString();
version = DBVersion.Parse(versionString);
if (!version.isAtLeast(5, 0, 0))
throw new NotSupportedException(Resources.ServerTooOld);
threadId = packet.ReadInteger(4);
encryptionSeed = packet.ReadString();
maxSinglePacket = (256 * 256 * 256) - 1;
// read in Server capabilities if they are provided
ClientFlags serverCaps = 0;
if (packet.HasMoreData)
serverCaps = (ClientFlags)packet.ReadInteger(2);
/* New protocol with 16 bytes to describe server characteristics */
owner.ConnectionCharSetIndex = (int)packet.ReadByte();
serverStatus = (ServerStatusFlags)packet.ReadInteger(2);
// Since 5.5, high bits of server caps are stored after status.
// Previously, it was part of reserved always 0x00 13-byte filler.
uint serverCapsHigh = (uint)packet.ReadInteger(2);
serverCaps |= (ClientFlags)(serverCapsHigh << 16);
packet.Position += 11;
string seedPart2 = packet.ReadString();
encryptionSeed += seedPart2;
string authenticationMethod = "";
if ((serverCaps & ClientFlags.PLUGIN_AUTH) != 0)
{
authenticationMethod = packet.ReadString();
}
else
{
// Some MySql versions like 5.1, don't give name of plugin, default to native password.
authenticationMethod = "mysql_native_password";
}
// based on our settings, set our connection flags
SetConnectionFlags(serverCaps);
packet.Clear();
packet.WriteInteger((int)connectionFlags, 4);
#if !CF
if ((serverCaps & ClientFlags.SSL) == 0)
{
if ((Settings.SslMode != MySqlSslMode.None)
&& (Settings.SslMode != MySqlSslMode.Preferred))
//.........这里部分代码省略.........
示例4: 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)'\'');
}
}
示例5: Open
public void Open()
{
// connect to one of our specified hosts
try
{
baseStream = StreamCreator.GetStream(Settings);
//#if !CF && !RT
// if (Settings.IncludeSecurityAsserts)
// MySqlSecurityPermission.CreatePermissionSet(false).Assert();
//#endif
}
catch (System.Security.SecurityException)
{
throw;
}
catch (Exception ex)
{
throw new MySqlException("Resources.UnableToConnectToHost",
(int)MySqlErrorCode.UnableToConnectToHost, ex);
}
if (baseStream == null)
throw new MySqlException("Resources.UnableToConnectToHost",
(int)MySqlErrorCode.UnableToConnectToHost);
int maxSinglePacket = 255 * 255 * 255;
stream = new MySqlStream(baseStream, Encoding, false);
stream.ResetTimeout((int)Settings.ConnectionTimeout * 1000);
// read off the welcome packet and parse out it's values
packet = stream.ReadPacket();
int protocol = packet.ReadByte();
string versionString = packet.ReadString();
owner.isFabric = versionString.EndsWith("fabric", StringComparison.OrdinalIgnoreCase);
version = DBVersion.Parse(versionString);
if (!owner.isFabric && !version.isAtLeast(5, 0, 0))
throw new NotSupportedException("Resources.ServerTooOld");
threadId = packet.ReadInteger(4);
byte[] seedPart1 = packet.ReadStringAsBytes();
maxSinglePacket = (256 * 256 * 256) - 1;
// read in Server capabilities if they are provided
ClientFlags serverCaps = 0;
if (packet.HasMoreData)
serverCaps = (ClientFlags)packet.ReadInteger(2);
/* New protocol with 16 bytes to describe server characteristics */
owner.ConnectionCharSetIndex = (int)packet.ReadByte();
serverStatus = (ServerStatusFlags)packet.ReadInteger(2);
// Since 5.5, high bits of server caps are stored after status.
// Previously, it was part of reserved always 0x00 13-byte filler.
uint serverCapsHigh = (uint)packet.ReadInteger(2);
serverCaps |= (ClientFlags)(serverCapsHigh << 16);
packet.Position += 11;
byte[] seedPart2 = packet.ReadStringAsBytes();
encryptionSeed = new byte[seedPart1.Length + seedPart2.Length];
seedPart1.CopyTo(encryptionSeed, 0);
seedPart2.CopyTo(encryptionSeed, seedPart1.Length);
string authenticationMethod = "";
if ((serverCaps & ClientFlags.PLUGIN_AUTH) != 0)
{
authenticationMethod = packet.ReadString();
}
else
{
// Some MySql versions like 5.1, don't give name of plugin, default to native password.
authenticationMethod = "mysql_native_password";
}
// based on our settings, set our connection flags
SetConnectionFlags(serverCaps);
packet.Clear();
packet.WriteInteger((int)connectionFlags, 4);
packet.WriteInteger(maxSinglePacket, 4);
packet.WriteByte(33); //character set utf-8
packet.Write(new byte[23]);
#if !CF && !RT
if ((serverCaps & ClientFlags.SSL) == 0)
{
if ((Settings.SslMode != MySqlSslMode.None)
&& (Settings.SslMode != MySqlSslMode.Preferred))
{
// Client requires SSL connections.
string message = String.Format("Resources.NoServerSSLSupport",
Settings.Server);
throw new MySqlException(message);
}
}
else if (Settings.SslMode != MySqlSslMode.None)
{
//.........这里部分代码省略.........
示例6: Open
public void Open()
{
// connect to one of our specified hosts
try
{
#if !CF
if (Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory)
{
SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName);
str.Open(Settings.ConnectionTimeout);
baseStream = str;
}
else
{
#endif
string pipeName = Settings.PipeName;
if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe)
pipeName = null;
StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName,
Settings.Keepalive);
baseStream = sc.GetStream(Settings.ConnectionTimeout);
#if !CF
}
#endif
}
catch (Exception ex)
{
throw new MySqlException(MySqlResources.UnableToConnectToHost,
(int) MySqlErrorCode.UnableToConnectToHost, ex);
}
if (baseStream == null)
throw new MySqlException(MySqlResources.UnableToConnectToHost,
(int)MySqlErrorCode.UnableToConnectToHost);
int maxSinglePacket = 255*255*255;
stream = new MySqlStream(baseStream, Encoding, false);
stream.ResetTimeout((int)Settings.ConnectionTimeout*1000);
// read off the welcome packet and parse out it's values
packet = stream.ReadPacket();
int protocol = packet.ReadByte();
string versionString = packet.ReadString();
version = DBVersion.Parse(versionString);
if (!version.isAtLeast(4, 1, 1))
throw new NotSupportedException(MySqlResources.ServerTooOld);
threadId = packet.ReadInteger(4);
encryptionSeed = packet.ReadString();
maxSinglePacket = (256*256*256) - 1;
// read in Server capabilities if they are provided
ClientFlags serverCaps = 0;
if (packet.HasMoreData)
serverCaps = (ClientFlags) packet.ReadInteger(2);
/* New protocol with 16 bytes to describe server characteristics */
owner.ConnectionCharSetIndex = (int)packet.ReadByte();
serverStatus = (ServerStatusFlags) packet.ReadInteger(2);
packet.Position += 13;
string seedPart2 = packet.ReadString();
encryptionSeed += seedPart2;
// based on our settings, set our connection flags
SetConnectionFlags(serverCaps);
packet.Clear();
packet.WriteInteger((int) connectionFlags, 4);
#if !CF
if ((serverCaps & ClientFlags.SSL) ==0)
{
if ((Settings.SslMode != MySqlSslMode.None)
&& (Settings.SslMode != MySqlSslMode.Preferred))
{
// Client requires SSL connections.
string message = String.Format(MySqlResources.NoServerSSLSupport,
Settings.Server);
throw new MySqlException(message);
}
}
else if (Settings.SslMode != MySqlSslMode.None)
{
stream.SendPacket(packet);
StartSSL();
packet.Clear();
packet.WriteInteger((int) connectionFlags, 4);
}
#endif
packet.WriteInteger(maxSinglePacket, 4);
packet.WriteByte(8);
packet.Write(new byte[23]);
Authenticate();
// if we are using compression, then we use our CompressedStream class
// to hide the ugliness of managing the compression
//.........这里部分代码省略.........