GetCommandText() private method

This method substitutes the Parameters, if exist, in the command to their actual values. The parameter name format is :ParameterName.
private GetCommandText ( ) : byte[]
return byte[]
コード例 #1
0
        public void WriteToStream(Stream outputStream, Encoding encoding)
        {
            //NpgsqlEventLog.LogMsg( this.ToString() + _commandText, LogLevel.Debug  );


            String commandText = _command.GetCommandText();

            // Tell to mediator what command is being sent.

            _command.Connector.Mediator.SqlSent = commandText;

            // Send the query to server.
            // Write the byte 'Q' to identify a query message.
            outputStream.WriteByte((Byte)'Q');

            if (_protocolVersion == ProtocolVersion.Version3)
            {
                // Write message length. Int32 + string length + null terminator.
                PGUtil.WriteInt32(outputStream, 4 + encoding.GetByteCount(commandText) + 1);
            }

            // Write the query. In this case it is the CommandText text.
            // It is a string terminated by a C NULL character.
            PGUtil.WriteString(commandText, outputStream, encoding);
        }
コード例 #2
0
ファイル: NpgsqlQuery.cs プロジェクト: mdeutcher/Npgsql2
        public override void WriteToStream(Stream outputStream)
        {
            //NpgsqlEventLog.LogMsg( this.ToString() + _commandText, LogLevel.Debug  );

            byte[] commandText = _command.GetCommandText();

            if (NpgsqlEventLog.Level >= LogLevel.Debug)
            {
                // Log the string being sent.
                PGUtil.LogStringWritten(BackendEncoding.UTF8Encoding.GetString(commandText));
            }

            // Tell to mediator what command is being sent.
            _command.Connector.Mediator.SetSqlSent(commandText);

            // Workaround for seek exceptions when running under ms.net. TODO: Check why Npgsql may be letting behind data in the stream.
            // Whatever issue there was here seems to be rectified.  Leaving it active, per Francisco.
            // The problem is not well understood.  Needs more checking.
            // [email protected]       09/20/2013
            outputStream.Flush();

            // Send the query to server.
            // Write the byte 'Q' to identify a query message.
            outputStream.WriteByte((byte)FrontEndMessageCode.Query);

            if (_protocolVersion == ProtocolVersion.Version3)
            {
                // Write message length. Int32 + string length + null terminator.
                PGUtil.WriteInt32(outputStream, 4 + commandText.Length + 1);
            }

            outputStream.WriteBytesNullTerminated(commandText);
        }
コード例 #3
0
        public override void WriteToStream(Stream outputStream)
        {
            //NpgsqlEventLog.LogMsg( this.ToString() + _commandText, LogLevel.Debug  );


            StringBuilder commandText = _command.GetCommandText();



            // Log the string being sent.



            if (NpgsqlEventLog.Level >= LogLevel.Debug)
            {
                PGUtil.LogStringWritten(commandText.ToString());
            }



            // This method needs refactory.

            // The code below which deals with writing string to stream needs to be redone to use

            // PGUtil.WriteString() as before. The problem is that WriteString is using too much strings (concatenation).

            // Find a way to optimize that.



            // Tell to mediator what command is being sent.

            _command.Connector.Mediator.SetSqlSent(commandText);

            // Workaround for seek exceptions when running under ms.net. TODO: Check why Npgsql may be letting behind data in the stream.
            outputStream.Flush();

            // Send the query to server.
            // Write the byte 'Q' to identify a query message.
            outputStream.WriteByte((byte)FrontEndMessageCode.Query);

            //Work out the encoding of the string (null-terminated) once and take the length from having done so
            //rather than doing so repeatedly.
            byte[] bytes = UTF8Encoding.GetBytes(commandText.Append('\x00').ToString());

            if (_protocolVersion == ProtocolVersion.Version3)
            {
                // Write message length. Int32 + string length + null terminator.
                PGUtil.WriteInt32(outputStream, 4 + bytes.Length);
            }

            outputStream.Write(bytes, 0, bytes.Length);
        }