本文整理汇总了C#中MySql.Data.MySqlClient.MySqlPacket类的典型用法代码示例。如果您正苦于以下问题:C# MySqlPacket类的具体用法?C# MySqlPacket怎么用?C# MySqlPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySqlPacket类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MySqlException
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
if (!(val is TimeSpan))
throw new MySqlException("Only TimeSpan objects can be serialized by MySqlTimeSpan");
TimeSpan ts = (TimeSpan)val;
bool negative = ts.TotalMilliseconds < 0;
ts = ts.Duration();
if (binary)
{
packet.WriteByte(8);
packet.WriteByte((byte)(negative ? 1 : 0));
packet.WriteInteger(ts.Days, 4);
packet.WriteByte((byte)ts.Hours);
packet.WriteByte((byte)ts.Minutes);
packet.WriteByte((byte)ts.Seconds);
}
else
{
String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'",
negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
packet.WriteStringNoNull(s);
}
}
示例2:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
var v = (val is double) ? (double)val : Convert.ToDouble(val);
if (binary)
packet.Write(BitConverter.GetBytes(v));
else
packet.WriteStringNoNull(v.ToString("R", CultureInfo.InvariantCulture));
}
示例3:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
ulong v = (val is ulong) ? (ulong)val : Convert.ToUInt64(val);
if (binary)
packet.WriteInteger((long)v, 8);
else
packet.WriteStringNoNull(v.ToString());
}
示例4:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
int v = (val is Int32) ? (int)val : Convert.ToInt32(val);
if (binary)
packet.WriteInteger((long)v, 2);
else
packet.WriteStringNoNull(v.ToString());
}
示例5:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
var v = (val is Int64) ? (Int64)val : Convert.ToInt64(val);
if (binary)
packet.WriteInteger(v, 8);
else
packet.WriteStringNoNull(v.ToString());
}
示例6: WriteValue
public void WriteValue(MySqlPacket packet, bool binary, object value, int length)
{
ulong v = (value is UInt64) ? (UInt64)value : Convert.ToUInt64(value);
if (binary)
packet.WriteInteger((long)v, 8);
else
packet.WriteStringNoNull(v.ToString());
}
示例7:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
byte v = (val is byte) ? (byte)val : Convert.ToByte(val);
if (binary)
packet.WriteByte(v);
else
packet.WriteStringNoNull(v.ToString());
}
示例8: ExecuteStatement
public override void ExecuteStatement(MySqlPacket packetToExecute)
{
base.ExecuteStatement(packetToExecute);
int pos = packetToExecute.Position;
packetToExecute.Position = 1;
int statementId = packetToExecute.ReadInteger(4);
packetToExecute.Position = pos;
MySqlTrace.TraceEvent(TraceEventType.Information, MySqlTraceEventType.StatementExecuted,
Resources.TraceStatementExecuted, driverId, statementId, ThreadID);
}
示例9: MySqlStream
public MySqlStream(Encoding encoding)
{
// we have no idea what the real value is so we start off with the max value
// The real value will be set in NativeDriver.Configure()
maxPacketSize = ulong.MaxValue;
// we default maxBlockSize to MaxValue since we will get the 'real' value in
// the authentication handshake and we know that value will not exceed
// true maxBlockSize prior to that.
maxBlockSize = Int32.MaxValue;
packet = new MySqlPacket(encoding);
}
示例10:
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) + "'");
}
示例11: SendQuery
public override void SendQuery(MySqlPacket p)
{
rowSizeInBytes = 0;
string cmdText = Encoding.GetString(p.Buffer, 5, p.Length - 5);
string normalized_query = null;
if (cmdText.Length > 300)
{
QueryNormalizer normalizer = new QueryNormalizer();
normalized_query = normalizer.Normalize(cmdText);
cmdText = cmdText.Substring(0, 300);
}
base.SendQuery(p);
MySqlTrace.TraceEvent(TraceEventType.Information, MySqlTraceEventType.QueryOpened,
Resources.TraceQueryOpened, driverId, ThreadID, cmdText);
if (normalized_query != null)
MySqlTrace.TraceEvent(TraceEventType.Information, MySqlTraceEventType.QueryNormalized,
Resources.TraceQueryNormalized, driverId, ThreadID, normalized_query);
}
示例12: MySqlBinary
IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal)
{
MySqlBinary b;
if (nullVal)
b = new MySqlBinary(type, true);
else
{
if (length == -1)
length = (long)packet.ReadFieldLength();
byte[] newBuff = new byte[length];
packet.Read(newBuff, 0, (int)length);
b = new MySqlBinary(type, newBuff);
}
return b;
}
示例13: MySqlByte
IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal)
{
if (nullVal)
return new MySqlByte(true);
if (length == -1)
return new MySqlByte((sbyte)packet.ReadByte());
else
{
string s = packet.ReadString(length);
MySqlByte b = new MySqlByte(SByte.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture));
b.TreatAsBoolean = TreatAsBoolean;
return b;
}
}
示例14: SendPacket
public void SendPacket(MySqlPacket packet)
{
byte[] buffer = packet.Buffer;
int length = packet.Position-4;
if ((ulong)length > maxPacketSize)
throw new MySqlException(Resources.QueryTooLarge, (int)MySqlErrorCode.PacketTooLarge);
int offset = 0;
while (length > 0)
{
int lenToSend = length > maxBlockSize ? maxBlockSize : length;
buffer[offset] = (byte)(lenToSend & 0xff);
buffer[offset+1] = (byte)((lenToSend >> 8) & 0xff);
buffer[offset+2] = (byte)((lenToSend >> 16) & 0xff);
buffer[offset+3] = sequenceByte++;
outStream.Write(buffer, offset, lenToSend + 4);
outStream.Flush();
length -= lenToSend;
offset += lenToSend;
}
}
示例15: Prepare
public virtual void Prepare()
{
// strip out names from parameter markers
string text;
List<string> parameter_names = PrepareCommandText(out text);
// ask our connection to send the prepare command
MySqlField[] paramList = null;
statementId = Driver.PrepareStatement(text, ref paramList);
// now we need to assign our field names since we stripped them out
// for the prepare
for (int i = 0; i < parameter_names.Count; i++)
{
//paramList[i].ColumnName = (string) parameter_names[i];
string parameterName = (string)parameter_names[i];
MySqlParameter p = Parameters.GetParameterFlexible(parameterName, false);
if (p == null)
throw new InvalidOperationException(
String.Format(Resources.ParameterNotFoundDuringPrepare, parameterName));
p.Encoding = paramList[i].Encoding;
parametersToSend.Add(p);
}
// now prepare our null map
int numNullBytes = 0;
if (paramList != null && paramList.Length > 0)
{
nullMap = new BitArray(paramList.Length);
numNullBytes = (nullMap.Count + 7) / 8;
}
packet = new MySqlPacket(Driver.Encoding);
// write out some values that do not change run to run
packet.WriteByte(0);
packet.WriteInteger(statementId, 4);
packet.WriteByte((byte)0); // flags; always 0 for 4.1
packet.WriteInteger(1, 4); // interation count; 1 for 4.1
nullMapPosition = packet.Position;
packet.Position += numNullBytes; // leave room for our null map
packet.WriteByte(1); // rebound flag
// write out the parameter types
foreach (MySqlParameter p in parametersToSend)
packet.WriteInteger(p.GetPSType(), 2);
dataPosition = packet.Position;
}