本文整理汇总了C#中MySql.Data.MySqlClient.MySqlStream类的典型用法代码示例。如果您正苦于以下问题:C# MySqlStream类的具体用法?C# MySqlStream怎么用?C# MySqlStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MySqlStream类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:26,代码来源:MySqlTime.cs
示例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());
}
开发者ID:tdhieu,项目名称:openvss,代码行数:8,代码来源:MySqlInt16.cs
示例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());
}
开发者ID:tdhieu,项目名称:openvss,代码行数:8,代码来源:MySqlUByte.cs
示例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());
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:8,代码来源:MySqlBit.cs
示例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));
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:9,代码来源:MySqlSingle.cs
示例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;
}
开发者ID:BjkGkh,项目名称:R106,代码行数:8,代码来源:SSPI.cs
示例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);
}
开发者ID:tdhieu,项目名称:openvss,代码行数:9,代码来源:parameter.cs
示例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;
}
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:12,代码来源:NativeDriver.cs
示例9:
void IMySqlValue.SkipValue(MySqlStream stream)
{
int len = stream.ReadByte();
stream.SkipBytes(len);
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:5,代码来源:MySqlTime.cs
示例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);
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:44,代码来源:MySqlDateTime.cs
示例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 + "'");
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:17,代码来源:MySqlDateTime.cs
示例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));
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:12,代码来源:MySqlUInt32.cs
示例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)));
}
开发者ID:tdhieu,项目名称:openvss,代码行数:10,代码来源:MySqlInt64.cs
示例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;
}
开发者ID:rykr,项目名称:connector-net,代码行数:26,代码来源:Statement.cs
示例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);
}
}
开发者ID:rykr,项目名称:connector-net,代码行数:33,代码来源:Statement.cs
示例16:
void IMySqlValue.SkipValue(MySqlStream stream)
{
long len = stream.ReadFieldLength();
stream.SkipBytes((int)len);
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:5,代码来源:MySqlString.cs
示例17: EscapeString
void IMySqlValue.WriteValue(MySqlStream stream, 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)
stream.WriteLenString(v);
else
stream.WriteStringNoNull("'" + EscapeString(v) + "'");
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:14,代码来源:MySqlString.cs
示例18: ParseMySql
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
{
if (nullVal) return new MySqlDateTime(type, true);
if (length >= 0)
{
string value = stream.ReadString(length);
return ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
}
long bufLength = stream.ReadByte();
int year = 0, month = 0, day = 0;
int hour = 0, minute = 0, second = 0;
if (bufLength >= 4)
{
year = stream.ReadInteger(2);
month = stream.ReadByte();
day = stream.ReadByte();
}
if (bufLength > 4)
{
hour = stream.ReadByte();
minute = stream.ReadByte();
second = stream.ReadByte();
}
if (bufLength > 7)
stream.ReadInteger(4);
return new MySqlDateTime(type, year, month, day, hour, minute, second);
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:33,代码来源:MySqlDateTime.cs
示例19: if
IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
{
if (nullVal) return new MySqlTimeSpan(true);
if (length >= 0)
{
string value = stream.ReadString(length);
ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
return this;
}
long bufLength = stream.ReadByte();
int negate = 0;
if (bufLength > 0)
negate = stream.ReadByte();
isNull = false;
if (bufLength == 0)
isNull = true;
else if (bufLength == 5)
mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
else if (bufLength == 8)
mValue = new TimeSpan(stream.ReadInteger(4),
stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
else
mValue = new TimeSpan(stream.ReadInteger(4),
stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
stream.ReadInteger(4) / 1000000);
if (negate == 1)
mValue = mValue.Negate();
return this;
}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:33,代码来源:MySqlTime.cs
示例20: 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)
{
//.........这里部分代码省略.........
开发者ID:yalunwang,项目名称:DotnetSpider,代码行数:101,代码来源:NativeDriver.cs
注:本文中的MySql.Data.MySqlClient.MySqlStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论