Ejemplo n.º 1
0
        public override void WriteToStream(Stream outputStream)
        {
            outputStream.WriteByte((byte)FrontEndMessageCode.Parse);

            // message length =
            // Int32 self
            // name of prepared statement + 1 null string terminator +
            // query string + 1 null string terminator
            // + Int16
            // + Int32 * number of parameters.
            Int32 messageLength = 4 + UTF8Encoding.GetByteCount(_prepareName) + 1 + UTF8Encoding.GetByteCount(_queryString) + 1 +
                                  2 + (_parameterIDs.Length * 4);

            //Int32 messageLength = 4 + _prepareName.Length + 1 + _queryString.Length + 1 + 2 + (_parameterIDs.Length * 4);

            PGUtil.WriteInt32(outputStream, messageLength);
            PGUtil.WriteString(_prepareName, outputStream);
            PGUtil.WriteString(_queryString, outputStream);
            PGUtil.WriteInt16(outputStream, (Int16)_parameterIDs.Length);


            for (Int32 i = 0; i < _parameterIDs.Length; i++)
            {
                PGUtil.WriteInt32(outputStream, _parameterIDs[i]);
            }
        }
Ejemplo n.º 2
0
        public override void WriteToStream(Stream outputStream)
        {
            Int32 messageLength = 4 + UTF8Encoding.GetByteCount(_portalName) + 1 +
                                  UTF8Encoding.GetByteCount(_preparedStatementName) + 1 + 2 + (_parameterFormatCodes.Length * 2) +
                                  2;


            // Get size of parameter values.
            Int32 i;

            if (_parameterValues != null)
            {
                for (i = 0; i < _parameterValues.Length; i++)
                {
                    messageLength += 4;
                    if (_parameterValues[i] != null)
                    {
                        if (((_parameterFormatCodes.Length == 1) && (_parameterFormatCodes[0] == (Int16)FormatCode.Binary)) ||
                            ((_parameterFormatCodes.Length != 1) && (_parameterFormatCodes[i] == (Int16)FormatCode.Binary)))
                        {
                            messageLength += ((Byte[])_parameterValues[i]).Length;
                        }
                        else
                        {
                            messageLength += UTF8Encoding.GetByteCount((String)_parameterValues[i]);
                        }
                    }
                }
            }

            messageLength += 2 + (_resultFormatCodes.Length * 2);


            outputStream.WriteByte((byte)FrontEndMessageCode.Bind);

            PGUtil.WriteInt32(outputStream, messageLength);
            PGUtil.WriteString(_portalName, outputStream);
            PGUtil.WriteString(_preparedStatementName, outputStream);

            PGUtil.WriteInt16(outputStream, (Int16)_parameterFormatCodes.Length);

            for (i = 0; i < _parameterFormatCodes.Length; i++)
            {
                PGUtil.WriteInt16(outputStream, _parameterFormatCodes[i]);
            }

            if (_parameterValues != null)
            {
                PGUtil.WriteInt16(outputStream, (Int16)_parameterValues.Length);

                for (i = 0; i < _parameterValues.Length; i++)
                {
                    if (((_parameterFormatCodes.Length == 1) && (_parameterFormatCodes[0] == (Int16)FormatCode.Binary)) ||
                        ((_parameterFormatCodes.Length != 1) && (_parameterFormatCodes[i] == (Int16)FormatCode.Binary)))
                    {
                        Byte[] parameterValue = (Byte[])_parameterValues[i];
                        if (parameterValue == null)
                        {
                            PGUtil.WriteInt32(outputStream, -1);
                        }
                        else
                        {
                            PGUtil.WriteInt32(outputStream, parameterValue.Length);
                            outputStream.Write(parameterValue, 0, parameterValue.Length);
                        }
                    }
                    else
                    {
                        if ((_parameterValues[i] == null))
                        {
                            PGUtil.WriteInt32(outputStream, -1);
                        }
                        else
                        {
                            Byte[] parameterValueBytes = UTF8Encoding.GetBytes((String)_parameterValues[i]);
                            PGUtil.WriteInt32(outputStream, parameterValueBytes.Length);
                            outputStream.Write(parameterValueBytes, 0, parameterValueBytes.Length);
                        }
                    }
                }
            }
            else
            {
                PGUtil.WriteInt16(outputStream, 0);
            }

            PGUtil.WriteInt16(outputStream, (Int16)_resultFormatCodes.Length);
            for (i = 0; i < _resultFormatCodes.Length; i++)
            {
                PGUtil.WriteInt16(outputStream, _resultFormatCodes[i]);
            }
        }