コード例 #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]);
            }
        }
コード例 #2
0
ファイル: NpgsqlDescribe.cs プロジェクト: zhxjdwh/revenj
        public static void Send(char what, string portal, Stream outputStream)
        {
            outputStream.WriteByte((byte)FrontEndMessageCode.Describe);

            PGUtil.WriteInt32(outputStream, 4 + 1 + UTF8Encoding.GetByteCount(portal) + 1);

            outputStream.WriteByte((Byte)what);
            PGUtil.WriteString(portal, outputStream);
        }
コード例 #3
0
ファイル: NpgsqlExecute.cs プロジェクト: zhxjdwh/revenj
        public override void WriteToStream(Stream outputStream)
        {
            outputStream.WriteByte((byte)FrontEndMessageCode.Execute);

            PGUtil.WriteInt32(outputStream, 4 + UTF8Encoding.GetByteCount(_portalName) + 1 + 4);

            PGUtil.WriteString(_portalName, outputStream);
            PGUtil.WriteInt32(outputStream, _maxRows);
        }
コード例 #4
0
        public void TestNotify(NpgsqlConnector context)
        {
            //ZA  Hnotifytest CNOTIFY Z
            //Qlisten notifytest;notify notifytest;
            Stream stm        = context.Stream;
            string uuidString = "uuid" + Guid.NewGuid().ToString("N");

            PGUtil.WriteString("Qlisten " + uuidString + ";notify " + uuidString + ";", stm);
            Queue <byte> buffer = new Queue <byte>();

            byte[] convertBuffer = new byte[36];
            for (; ;)
            {
                int newByte = stm.ReadByte();
                if (newByte == -1)
                {
                    throw new EndOfStreamException();
                }
                buffer.Enqueue((byte)newByte);
                if (buffer.Count > 35)
                {
                    buffer.CopyTo(convertBuffer, 0);
                    if (ENCODING_UTF8.GetString(convertBuffer) == uuidString)
                    {
                        for (; ;)
                        {
                            switch (stm.ReadByte())
                            {
                            case -1:
                                throw new EndOfStreamException();

                            case 'Z':
                                //context.Query(new NpgsqlCommand("UNLISTEN *", context));
                                using (NpgsqlCommand cmd = new NpgsqlCommand("UNLISTEN *", context))
                                {
                                    context.Query(cmd);
                                }
                                return;
                            }
                        }
                    }
                    else
                    {
                        buffer.Dequeue();
                    }
                }
            }
        }
コード例 #5
0
        public override void WriteToStream(Stream output_stream)
        {
            PGUtil.WriteInt32(output_stream,
                              4 + 4 + 5 + (UTF8Encoding.GetByteCount(user_name) + 1) + 9 +
                              (UTF8Encoding.GetByteCount(database_name) + 1) + 10 + 4 + 1);

            PGUtil.WriteInt32(output_stream, 196608);
            // User name.
            PGUtil.WriteString("user", output_stream);
            // User name.
            PGUtil.WriteString(user_name, output_stream);
            // Database name.
            PGUtil.WriteString("database", output_stream);
            // Database name.
            PGUtil.WriteString(database_name, output_stream);
            // DateStyle.
            PGUtil.WriteString("DateStyle", output_stream);
            // DateStyle.
            PGUtil.WriteString("ISO", output_stream);

            output_stream.WriteByte(0);
            output_stream.Flush();
        }
コード例 #6
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]);
            }
        }