本文整理汇总了C#中MySql.Data.MySqlClient.MySqlStream类的典型用法代码示例。如果您正苦于以下问题:C# MySqlStream类的具体用法?C# MySqlStream怎么用?C# MySqlStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySqlStream类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MySqlException
void IMySqlValue.WriteValue(MySqlStream stream, 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)
{
stream.WriteByte(8);
stream.WriteByte((byte)(negative ? 1 : 0));
stream.WriteInteger(ts.Days, 4);
stream.WriteByte((byte)ts.Hours);
stream.WriteByte((byte)ts.Minutes);
stream.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);
stream.WriteStringNoNull(s);
}
}
示例2:
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
{
int v = Convert.ToInt32(val);
if (binary)
stream.Write(BitConverter.GetBytes(v));
else
stream.WriteStringNoNull(v.ToString());
}
示例3:
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
{
byte v = ((IConvertible)val).ToByte(null);
if (binary)
stream.WriteByte((byte)v);
else
stream.WriteStringNoNull(v.ToString());
}
示例4: WriteValue
public void WriteValue(MySqlStream stream, bool binary, object value, int length)
{
ulong v = Convert.ToUInt64(value);
if (binary)
stream.Write(BitConverter.GetBytes(v));
else
stream.WriteStringNoNull(v.ToString());
}
示例5:
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
{
Single v = Convert.ToSingle(val);
if (binary)
stream.Write(BitConverter.GetBytes(v));
else
stream.WriteStringNoNull(v.ToString("R",
CultureInfo.InvariantCulture));
}
示例6: SSPI
public SSPI(string targetName, MySqlStream stream, int seqNo, DBVersion version)
{
this.targetName = null;
this.stream = stream;
packetHeader = new byte[4];
seq = seqNo;
this.version = version;
}
示例7: Serialize
internal void Serialize(MySqlStream stream, bool binary)
{
IMySqlValue v = MySqlField.GetIMySqlValue(mySqlDbType);
if (!binary && (paramValue == null || paramValue == DBNull.Value))
stream.WriteStringNoNull("NULL");
else
v.WriteValue(stream, binary, paramValue, size);
}
示例8: StartSSL
private void StartSSL()
{
RemoteCertificateValidationCallback sslValidateCallback =
new RemoteCertificateValidationCallback(ServerCheckValidation);
SslStream ss = new SslStream(baseStream, true, sslValidateCallback, null);
X509CertificateCollection certs = GetClientCertificates();
ss.AuthenticateAsClient(Settings.Server, certs, SslProtocols.Default, false);
baseStream = ss;
stream = new MySqlStream(ss, Encoding, false);
stream.SequenceByte = 2;
}
示例9:
void IMySqlValue.SkipValue(MySqlStream stream)
{
int len = stream.ReadByte();
stream.SkipBytes(len);
}
示例10: if
void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object value, int length)
{
MySqlDateTime dtValue;
if (value is DateTime)
dtValue = new MySqlDateTime(type, (DateTime)value);
else if (value is string)
dtValue = new MySqlDateTime(type, DateTime.Parse((string)value,
System.Globalization.CultureInfo.CurrentCulture));
else if (value is MySqlDateTime)
dtValue = (MySqlDateTime)value;
else
throw new MySqlException("Unable to serialize date/time value.");
if (!binary)
{
SerializeText(stream, dtValue);
return;
}
if (type == MySqlDbType.Timestamp)
stream.WriteByte(11);
else
stream.WriteByte(7);
stream.WriteInteger(dtValue.Year, 2);
stream.WriteByte((byte)dtValue.Month);
stream.WriteByte((byte)dtValue.Day);
if (type == MySqlDbType.Date)
{
stream.WriteByte(0);
stream.WriteByte(0);
stream.WriteByte(0);
}
else
{
stream.WriteByte((byte)dtValue.Hour);
stream.WriteByte((byte)dtValue.Minute);
stream.WriteByte((byte)dtValue.Second);
}
if (type == MySqlDbType.Timestamp)
stream.WriteInteger(dtValue.Millisecond, 4);
}
示例11: SerializeText
private void SerializeText(MySqlStream stream, MySqlDateTime value)
{
string val = String.Empty;
if (type == MySqlDbType.Timestamp && !stream.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);
}
stream.WriteStringNoNull("'" + val + "'");
}
示例12:
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
{
if (nullVal)
return new MySqlUInt32((this as IMySqlValue).MySqlDbType, true);
if (length == -1)
return new MySqlUInt32((this as IMySqlValue).MySqlDbType,
(uint)stream.ReadInteger(4));
else
return new MySqlUInt32((this as IMySqlValue).MySqlDbType,
UInt32.Parse(stream.ReadString(length), NumberStyles.Any, CultureInfo.InvariantCulture));
}
示例13:
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
{
if (nullVal)
return new MySqlInt64(true);
if (length == -1)
return new MySqlInt64((long)stream.ReadLong(8));
else
return new MySqlInt64(Int64.Parse(stream.ReadString(length)));
}
示例14: SerializeParameter
/// <summary>
/// Serializes the given parameter to the given memory stream
/// </summary>
/// <remarks>
/// <para>This method is called by PrepareSqlBuffers to convert the given
/// parameter to bytes and write those bytes to the given memory stream.
/// </para>
/// </remarks>
/// <returns>True if the parameter was successfully serialized, false otherwise.</returns>
private bool SerializeParameter(MySqlParameterCollection parameters,
MySqlStream stream, string parmName)
{
MySqlParameter parameter = GetParameter(parameters, parmName);
if (parameter == null)
{
// if we are using old syntax, we can't throw exceptions for parameters
// not defined.
if (Connection.Settings.UseOldSyntax)
return false;
throw new MySqlException(
String.Format(Resources.ParameterMustBeDefined, parmName));
}
parameter.Serialize(stream, false);
return true;
}
示例15: BindParameters
protected virtual void BindParameters()
{
// tokenize the sql
ArrayList tokenArray = TokenizeSql(ResolvedCommandText);
MySqlStream stream = new MySqlStream(Driver.Encoding);
stream.Version = Driver.Version;
// make sure our token array ends with a ;
string lastToken = (string) tokenArray[tokenArray.Count - 1];
if (lastToken != ";")
tokenArray.Add(";");
foreach (String token in tokenArray)
{
if (token.Trim().Length == 0)
continue;
if (token == ";")
{
buffers.Add(stream.InternalBuffer);
stream = new MySqlStream(Driver.Encoding);
continue;
}
if (token[0] == Parameters.ParameterMarker)
{
if (SerializeParameter(Parameters, stream, token))
continue;
}
// our fall through case is to write the token to the byte stream
stream.WriteStringNoNull(token);
}
}