当前位置: 首页>>代码示例>>C#>>正文


C# MySqlStream.WriteByte方法代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlStream.WriteByte方法的具体用法?C# MySqlStream.WriteByte怎么用?C# MySqlStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySql.Data.MySqlClient.MySqlStream的用法示例。


在下文中一共展示了MySqlStream.WriteByte方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

		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

示例2: 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;
			if (binary)
			{
				stream.WriteByte(8);
				stream.WriteByte((byte)(ts.TotalSeconds < 0 ? 1 : 0));
				stream.WriteInteger(ts.Days, 4);
				stream.WriteByte((byte)ts.Hours);
				stream.WriteByte((byte)ts.Minutes);
				stream.WriteByte((byte)ts.Seconds);
			}
			else
			{
				stream.WriteStringNoNull(String.Format("'{0} {1:00}:{2:00}:{3:00}.{4}'",
			  ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds));
			}
		}
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:21,代码来源:MySqlTime.cs

示例3: MySqlDateTime

		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

示例4: Execute

        public override void Execute()
        {
            // if we are not prepared, then call down to our base
            if (!IsPrepared)
            {
                base.Execute();
                return;
            }

            MySqlStream stream = new MySqlStream(Driver.Encoding);

            //TODO: support long data here
            // create our null bitmap
            BitArray nullMap = new BitArray(Parameters.Count);

            // now we run through the parameters that PREPARE sent back and use
            // those names to index into the parameters the user gave us.
            // if the user set that parameter to NULL, then we set the null map
            // accordingly
            if (paramList != null)
                for (int x = 0; x < paramList.Length; x++)
                {
                    MySqlParameter p = Parameters[paramList[x].ColumnName];
                    if (p.Value == DBNull.Value || p.Value == null)
                        nullMap[x] = true;
                }
            byte[] nullMapBytes = new byte[(Parameters.Count + 7)/8];

            // we check this because Mono doesn't ignore the case where nullMapBytes
            // is zero length.
            if (nullMapBytes.Length > 0)
                nullMap.CopyTo(nullMapBytes, 0);

            // start constructing our packet
            stream.WriteInteger(statementId, 4);
            stream.WriteByte((byte) 0); // flags; always 0 for 4.1
            stream.WriteInteger(1, 4); // interation count; 1 for 4.1
            stream.Write(nullMapBytes);
            //if (parameters != null && parameters.Count > 0)
            stream.WriteByte(1); // rebound flag
            //else
            //	packet.WriteByte( 0 );
            //TODO:  only send rebound if parms change

            // write out the parameter types
            if (paramList != null)
            {
                foreach (MySqlField param in paramList)
                {
                    MySqlParameter parm = Parameters[param.ColumnName];
                    stream.WriteInteger(parm.GetPSType(), 2);
                }

                // now write out all non-null values
                foreach (MySqlField param in paramList)
                {
                    int index = Parameters.IndexOf(param.ColumnName);
                    if (index == -1)
                        throw new MySqlException("Parameter '" + param.ColumnName +
                                                 "' is not defined.");
                    MySqlParameter parm = Parameters[index];
                    if (parm.Value == DBNull.Value || parm.Value == null)
                        continue;

                    stream.Encoding = param.Encoding;
                    parm.Serialize(stream, true);
                }
            }

            executionCount++;

            Driver.ExecuteStatement(stream.InternalBuffer.ToArray());
        }
开发者ID:rykr,项目名称:connector-net,代码行数:73,代码来源:PreparableStatement.cs

示例5: Open

        public override void Open()
        {
            base.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);
                    baseStream = sc.GetStream(Settings.ConnectionTimeout);
#if !CF
                }
#endif
                if (baseStream == null)
                    throw new Exception();
            }
            catch (Exception ex)
            {
                throw new MySqlException(Resources.UnableToConnectToHost, 
                    (int) MySqlErrorCode.UnableToConnectToHost, ex);
            }

            if (baseStream == null)
                throw new MySqlException("Unable to connect to any of the specified MySQL hosts");

            int maxSinglePacket = 255*255*255;
            stream = new MySqlStream(baseStream, encoding, false);

            // read off the welcome packet and parse out it's values
            stream.OpenPacket();
            protocol = stream.ReadByte();
            string versionString = stream.ReadString();
            version = DBVersion.Parse(versionString);
            threadId = stream.ReadInteger(4);
            encryptionSeed = stream.ReadString();

            if (version.isAtLeast(4, 0, 8))
                maxSinglePacket = (256*256*256) - 1;

            // read in Server capabilities if they are provided
            serverCaps = 0;
            if (stream.HasMoreData)
                serverCaps = (ClientFlags) stream.ReadInteger(2);
            if (version.isAtLeast(4, 1, 1))
            {
                /* New protocol with 16 bytes to describe server characteristics */
                serverCharSetIndex = stream.ReadInteger(1);

                serverStatus = (ServerStatusFlags) stream.ReadInteger(2);
                stream.SkipBytes(13);
                string seedPart2 = stream.ReadString();
                encryptionSeed += seedPart2;
            }

            // based on our settings, set our connection flags
            SetConnectionFlags();

            stream.StartOutput(0, false);
            stream.WriteInteger((int) connectionFlags,
                                version.isAtLeast(4, 1, 0) ? 4 : 2);

#if !CF
            if (connectionString.UseSSL && (serverCaps & ClientFlags.SSL) != 0)
            {
                stream.Flush();

                StartSSL();

                stream.StartOutput(0, false);
                stream.WriteInteger((int) connectionFlags,
                                    version.isAtLeast(4, 1, 0) ? 4 : 2);
            }
#endif

            stream.WriteInteger(maxSinglePacket,
                                version.isAtLeast(4, 1, 0) ? 4 : 3);

            if (version.isAtLeast(4, 1, 1))
            {
                stream.WriteByte(8);
                stream.Write(new byte[23]);
            }

            Authenticate();

            // if we are using compression, then we use our CompressedStream class
            // to hide the ugliness of managing the compression
            if ((connectionFlags & ClientFlags.COMPRESS) != 0)
//.........这里部分代码省略.........
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:101,代码来源:NativeDriver.cs

示例6: EscapeByteArray

        private void EscapeByteArray(byte[] bytes, int length, MySqlStream stream)
        {
            //	System.IO.MemoryStream ms = (System.IO.MemoryStream)stream.Stream;
            //	ms.Capacity += (length * 2);

            for (int x = 0; x < length; x++)
            {
                byte b = bytes[x];
                if (b == '\0')
                {
                    stream.WriteByte((byte)'\\');
                    stream.WriteByte((byte)'0');
                }

                else if (b == '\\' || b == '\'' || b == '\"')
                {
                    stream.WriteByte((byte)'\\');
                    stream.WriteByte(b);
                }
                else
                    stream.WriteByte(b);
            }
        }
开发者ID:rykr,项目名称:connector-net,代码行数:23,代码来源:MySqlBinary.cs

示例7: if

        void IMySqlValue.WriteValue(MySqlStream stream, bool binary, object val, int length)
        {
            byte[] buffToWrite = null;

            if (val is System.Byte[])
                buffToWrite = (byte[])val;
            else if (val is Char[])
                buffToWrite = stream.Encoding.GetBytes(val as char[]);
            else
            {
                string s = val.ToString();
                if (length == 0)
                    length = s.Length;
                else
                    s = s.Substring(0, length);
                buffToWrite = stream.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)
            {
                stream.WriteLength(length);
                stream.Write(buffToWrite, 0, length);
            }
            else
            {
                if (stream.Version.isAtLeast(4, 1, 0))
                    stream.WriteStringNoNull("_binary ");

                stream.WriteByte((byte)'\'');
                EscapeByteArray(buffToWrite, length, stream);
                stream.WriteByte((byte)'\'');
            }
        }
开发者ID:rykr,项目名称:connector-net,代码行数:40,代码来源:MySqlBinary.cs


注:本文中的MySql.Data.MySqlClient.MySqlStream.WriteByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。