本文整理汇总了C#中MySql.Data.MySqlClient.MySqlPacket.WriteStringNoNull方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlPacket.WriteStringNoNull方法的具体用法?C# MySqlPacket.WriteStringNoNull怎么用?C# MySqlPacket.WriteStringNoNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlPacket
的用法示例。
在下文中一共展示了MySqlPacket.WriteStringNoNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
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());
}
示例3:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
int v = (val is UInt16) ? (UInt16)val : Convert.ToUInt16(val);
if (binary)
packet.WriteInteger((long)v, 2);
else
packet.WriteStringNoNull(v.ToString());
}
示例4:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
long v = (val is Int64) ? (Int64)val : Convert.ToInt64(val);
if (binary)
packet.WriteInteger(v, 8);
else
packet.WriteStringNoNull(v.ToString());
}
示例5:
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object v, int length)
{
uint val = (v is uint) ? (uint)v : Convert.ToUInt32(v);
if (binary)
packet.WriteInteger((long)val, is24Bit ? 3 : 4);
else
packet.WriteStringNoNull(val.ToString());
}
示例6: Guid
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")) + "'");
}
}
示例7: 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)'\'');
}
}
示例8:
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, is24Bit ? 3 : 4);
else
packet.WriteStringNoNull(v.ToString());
}
示例9: 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)'\'');
}
}
示例10: 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);
}
}
示例11: MySqlGeometry
void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int length)
{
byte[] buffToWrite = null;
try
{
buffToWrite = ((MySqlGeometry)val)._valBinary;
}
catch
{
buffToWrite = val as Byte[];
}
if (buffToWrite == null)
{
MySqlGeometry v = new MySqlGeometry(0, 0);
MySqlGeometry.TryParse(val.ToString(), out v);
buffToWrite = v._valBinary;
}
byte[] result = new byte[GEOMETRY_LENGTH];
for (int i = 0; i < buffToWrite.Length; i++)
{
if (buffToWrite.Length < GEOMETRY_LENGTH)
result[i + 4] = buffToWrite[i];
else
result[i] = buffToWrite[i];
}
packet.WriteStringNoNull("_binary ");
packet.WriteByte((byte)'\'');
EscapeByteArray(result, GEOMETRY_LENGTH, packet);
packet.WriteByte((byte)'\'');
}
示例12: SerializeText
private void SerializeText(MySqlPacket packet, MySqlDateTime value)
{
string val = String.Empty;
if (type == MySqlDbType.Timestamp && !packet.Version.isAtLeast(4, 1, 0))
val = String.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}",
value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second);
else
{
val = String.Format("{0:0000}-{1:00}-{2:00}",
value.Year, value.Month, value.Day);
if (type != MySqlDbType.Date)
val = String.Format("{0} {1:00}:{2:00}:{3:00}", val,
value.Hour, value.Minute, value.Second);
}
packet.WriteStringNoNull("'" + val + "'");
}
示例13: WriteValue
public void WriteValue(MySqlPacket packet, bool binary, object value, int length)
{
var v = (value is bool) ? (bool)value : Convert.ToBoolean(value);
if (binary)
packet.WriteInteger((long) (v ? 1 : 0), 8);
else
packet.WriteStringNoNull(v.ToString());
}
示例14: Serialize
internal void Serialize(MySqlPacket packet, bool binary, MySqlConnectionStringBuilder settings)
{
if (!binary && (paramValue == null || paramValue == DBNull.Value))
packet.WriteStringNoNull("NULL");
else
{
if (ValueObject.MySqlDbType == MySqlDbType.Guid)
{
var g = (MySqlGuid)ValueObject;
g.OldGuids = settings.OldGuids;
valueObject = g;
}
ValueObject.WriteValue(packet, binary, paramValue, size);
}
}
示例15:
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) + "'");
}