Пример #1
0
        public override void Bind(NpgsqlConnector context, NpgsqlBind bind)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Bind");

            Stream stream = context.Stream;

            bind.WriteToStream(stream);
            //stream.Flush();
        }
Пример #2
0
        public override void Bind(NpgsqlConnector context, NpgsqlBind bind)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Bind");

            Stream stream = context.Stream;

            bind.WriteToStream(stream);
            //stream.Flush();
        }
        private void PrepareInternal()
        {
            if (m_Connector.BackendProtocolVersion == ProtocolVersion.Version2)
            {
                planName            = Connector.NextPlanName();
                preparedCommandText = GetCommandText(true, false);

                ExecuteBlind(m_Connector, preparedCommandText);
                prepared = PrepareStatus.V2Prepared;

                // Tell to mediator what command is being sent.
                m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Prepare);
            }
            else
            {
                // Use the extended query parsing...
                planName = m_Connector.NextPlanName();
                String portalName = "";

                preparedCommandText = GetCommandText(true, true);
                NpgsqlParse    parse             = new NpgsqlParse(planName, preparedCommandText, new Int32[] { });
                NpgsqlDescribe statementDescribe = new NpgsqlDescribeStatement(planName);
                IEnumerable <IServerResponseObject> responseEnum;
                NpgsqlRowDescription returnRowDesc = null;

                // Write Parse, Describe, and Sync messages to the wire.
                m_Connector.Parse(parse);
                m_Connector.Describe(statementDescribe);
                m_Connector.Sync();

                // Tell to mediator what command is being sent.
                m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Parse);

                // Flush and wait for response.
                responseEnum = m_Connector.ProcessBackendResponsesEnum();

                // Look for a NpgsqlRowDescription in the responses, discarding everything else.
                foreach (IServerResponseObject response in responseEnum)
                {
                    if (response is NpgsqlRowDescription)
                    {
                        returnRowDesc = (NpgsqlRowDescription)response;
                    }
                    else if (response is IDisposable)
                    {
                        (response as IDisposable).Dispose();
                    }
                }

                Int16[] resultFormatCodes;

                if (returnRowDesc != null)
                {
                    resultFormatCodes = new Int16[returnRowDesc.NumFields];

                    for (int i = 0; i < returnRowDesc.NumFields; i++)
                    {
                        NpgsqlRowDescription.FieldData returnRowDescData = returnRowDesc[i];

                        if (returnRowDescData.TypeInfo != null)
                        {
                            // Binary format?
                            // PG always defaults to text encoding.  We can fix up the row description
                            // here based on support for binary encoding.  Once this is done,
                            // there is no need to request another row description after Bind.
                            returnRowDescData.FormatCode = returnRowDescData.TypeInfo.SupportsBinaryBackendData ? FormatCode.Binary : FormatCode.Text;
                            resultFormatCodes[i]         = (Int16)returnRowDescData.FormatCode;
                        }
                        else
                        {
                            // Text format (default).
                            resultFormatCodes[i] = (Int16)FormatCode.Text;
                        }
                    }
                }
                else
                {
                    resultFormatCodes = new Int16[] { 0 };
                }

                // Save the row description for use with all future Executes.
                currentRowDescription = returnRowDesc;

                // The Bind and Execute message objects live through multiple Executes.
                // Only Bind changes at all between Executes, which is done in BindParameters().
                bind    = new NpgsqlBind(portalName, planName, new Int16[Parameters.Count], null, resultFormatCodes);
                execute = new NpgsqlExecute(portalName, 0);

                prepared = PrepareStatus.V3Prepared;
            }
        }
Пример #4
0
        /// <summary>
        /// Creates a prepared version of the command on a PostgreSQL server.
        /// </summary>
        public override void Prepare()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Prepare");

            // Check the connection state.
            CheckConnectionState();

            // reset any responses just before getting new ones
            Connector.Mediator.ResetResponses();

            // Set command timeout.
            m_Connector.Mediator.CommandTimeout = CommandTimeout;

            if (!m_Connector.SupportsPrepare)
            {
                return; // Do nothing.
            }

            if (m_Connector.BackendProtocolVersion == ProtocolVersion.Version2)
            {
                using (NpgsqlCommand command = new NpgsqlCommand(GetPrepareCommandText(), m_Connector))
                {
                    command.ExecuteBlind();
                }
            }
            else
            {
                using (m_Connector.BlockNotificationThread())
                {
                    try
                    {
                        // Use the extended query parsing...
                        planName = m_Connector.NextPlanName();
                        String portalName = m_Connector.NextPortalName();

                        parse = new NpgsqlParse(planName, GetParseCommandText(), new Int32[] { });

                        m_Connector.Parse(parse);

                        // We need that because Flush() doesn't cause backend to send
                        // ReadyForQuery on error. Without ReadyForQuery, we don't return 
                        // from query extended processing.

                        // We could have used Connector.Flush() which sends us back a
                        // ReadyForQuery, but on postgresql server below 8.1 there is an error
                        // with extended query processing which hinders us from using it.
                        m_Connector.RequireReadyForQuery = false;
                        m_Connector.Flush();


                        // Description...
                        NpgsqlDescribe describe = new NpgsqlDescribe('S', planName);


                        m_Connector.Describe(describe);

                        NpgsqlRowDescription returnRowDesc = m_Connector.Sync();

                        Int16[] resultFormatCodes;


                        if (returnRowDesc != null)
                        {
                            resultFormatCodes = new Int16[returnRowDesc.NumFields];

                            for (int i = 0; i < returnRowDesc.NumFields; i++)
                            {
                                NpgsqlRowDescription.FieldData returnRowDescData = returnRowDesc[i];


                                if (returnRowDescData.TypeInfo != null && returnRowDescData.TypeInfo.NpgsqlDbType == NpgsqlDbType.Bytea)
                                {
                                    // Binary format
                                    resultFormatCodes[i] = (Int16)FormatCode.Binary;
                                }
                                else
                                {
                                    // Text Format
                                    resultFormatCodes[i] = (Int16)FormatCode.Text;
                                }
                            }
                        }
                        else
                        {
                            resultFormatCodes = new Int16[] { 0 };
                        }

                        bind = new NpgsqlBind("", planName, new Int16[Parameters.Count], null, resultFormatCodes);
                    }
                    catch (IOException e)
                    {
                        throw ClearPoolAndCreateException(e);
                    }
                    catch
                    {

                        // As per documentation:

                        // "[...] When an error is detected while processing any extended-query message,

                        // the backend issues ErrorResponse, then reads and discards messages until a

                        // Sync is reached, then issues ReadyForQuery and returns to normal message processing.[...]"

                        // So, send a sync command if we get any problems.



                        m_Connector.Sync();

                        throw;
                    }
                }
            }
        }
Пример #5
0
 public virtual void Bind(NpgsqlConnector context, NpgsqlBind bind)
 {
     throw new InvalidOperationException("Internal Error! " + this);
 }
Пример #6
0
 internal void Bind(NpgsqlBind bind)
 {
     CurrentState.Bind(this, bind);
 }
        /// <summary>
        /// Creates a prepared version of the command on a PostgreSQL server.
        /// </summary>
        public void Prepare()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Prepare");

            // Check the connection state.
            CheckConnectionState();

            if (! Connector.SupportsPrepare)
            {
                return;	// Do nothing.
            }

            if (connector.BackendProtocolVersion == ProtocolVersion.Version2)
            {
                NpgsqlCommand command = new NpgsqlCommand(GetPrepareCommandText(), connector );
                command.ExecuteNonQuery();
            }
            else
            {
                // Use the extended query parsing...
                //planName = "NpgsqlPlan" + Connector.NextPlanIndex();
                planName = Connector.NextPlanName();
                String portalName = Connector.NextPortalName();

                parse = new NpgsqlParse(planName, GetParseCommandText(), new Int32[] {});

                Connector.Parse(parse);
                Connector.Mediator.RequireReadyForQuery = false;
                Connector.Flush();

                // Check for errors and/or notifications and do the Right Thing.
                connector.CheckErrorsAndNotifications();

                bind = new NpgsqlBind("", planName, new Int16[] {0}, null, new Int16[] {0});
            }
        }
Пример #8
0
        private void PrepareInternal()
        {
            if (m_Connector.BackendProtocolVersion == ProtocolVersion.Version2)
            {
                using (NpgsqlCommand command = new NpgsqlCommand(GetPrepareCommandText(), m_Connector))
                {
                    command.ExecuteBlind();
                    prepared = PrepareStatus.V2Prepared;
                }
            }
            else
            {
                // Use the extended query parsing...
                planName = m_Connector.NextPlanName();
                String portalName = "";
                NpgsqlParse parse = new NpgsqlParse(planName, GetParseCommandText(), new Int32[] { });
                NpgsqlDescribe statementDescribe = new NpgsqlDescribeStatement(planName);
                IEnumerable<IServerResponseObject> responseEnum;
                NpgsqlRowDescription returnRowDesc = null;

                // Write Parse, Describe, and Sync messages to the wire.
                m_Connector.Parse(parse);
                m_Connector.Describe(statementDescribe);
                m_Connector.Sync();

                // Flush and wait for response.
                responseEnum = m_Connector.ProcessBackendResponsesEnum();

                // Look for a NpgsqlRowDescription in the responses, discarding everything else.
                foreach (IServerResponseObject response in responseEnum)
                {
                    if (response is NpgsqlRowDescription)
                    {
                        returnRowDesc = (NpgsqlRowDescription)response;
                    }
                    else if (response is IDisposable)
                    {
                        (response as IDisposable).Dispose();
                    }
                }

                Int16[] resultFormatCodes;

                if (returnRowDesc != null)
                {
                    resultFormatCodes = new Int16[returnRowDesc.NumFields];

                    for (int i = 0; i < returnRowDesc.NumFields; i++)
                    {
                        NpgsqlRowDescription.FieldData returnRowDescData = returnRowDesc[i];

                        if (returnRowDescData.TypeInfo != null)
                        {
                            // Binary format?
                            resultFormatCodes[i] = returnRowDescData.TypeInfo.SupportsBinaryBackendData ? (Int16)FormatCode.Binary : (Int16)FormatCode.Text;
                        }
                        else
                        {
                            // Text Format
                            resultFormatCodes[i] = (Int16)FormatCode.Text;
                        }
                    }
                }
                else
                {
                    resultFormatCodes = new Int16[] { 0 };
                }

                // The Bind and Execute message objects live through multiple Executes.
                // Only Bind changes at all between Executes, which is done in BindParameters().
                bind = new NpgsqlBind(portalName, planName, new Int16[Parameters.Count], null, resultFormatCodes);
                execute = new NpgsqlExecute(portalName, 0);
                prepared = PrepareStatus.V3Prepared;
            }
        }
Пример #9
0
 public virtual void Bind(NpgsqlConnector context, NpgsqlBind bind)
 {
     throw new InvalidOperationException("¬нутренн¤¤ ќшибка! " + this);
 }
Пример #10
0
 internal void Bind(NpgsqlBind bind)
 {
     _log.Debug("Sending bind message");
     bind.WriteToStream(Stream);
 }
        public override void Bind(NpgsqlConnector context, NpgsqlBind bind)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Bind");
            BufferedStream stream = new BufferedStream(context.Stream);
            bind.WriteToStream(stream, context.Encoding);
            stream.Flush();

        }
Пример #12
0
        void UnPrepare()
        {
            if (_prepared == PrepareStatus.Prepared)
            {
                _connector.ExecuteBlind("DEALLOCATE " + _planName);
                _bind = null;
                _execute = null;
                _currentRowDescription = null;
                _prepared = PrepareStatus.NeedsPrepare;
            }

            _preparedCommandText = null;
        }
Пример #13
0
        /// <summary>
        /// Creates a prepared version of the command on a PostgreSQL server.
        /// </summary>
        public void Prepare()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Prepare");

            // Check the connection state.
            CheckConnectionState();
            
            // reset any responses just before getting new ones
            Connector.Mediator.ResetResponses();
            
            // Set command timeout.
            connector.Mediator.CommandTimeout = CommandTimeout;

            if (! connector.SupportsPrepare)
            {
                return;	// Do nothing.
            }

            if (connector.BackendProtocolVersion == ProtocolVersion.Version2)
            {
                NpgsqlCommand command = new NpgsqlCommand(GetPrepareCommandText(), connector );
                command.ExecuteNonQuery();
            }
            else
            {
                try
                {
                    
                    connector.StopNotificationThread();
                    
                    // Use the extended query parsing...
                    planName = connector.NextPlanName();
                    String portalName = connector.NextPortalName();
    
                    parse = new NpgsqlParse(planName, GetParseCommandText(), new Int32[] {});
    
                    connector.Parse(parse);
                    
                    // We need that because Flush() doesn't cause backend to send
                    // ReadyForQuery on error. Without ReadyForQuery, we don't return 
                    // from query extended processing.
                    
                    // We could have used Connector.Flush() which sends us back a
                    // ReadyForQuery, but on postgresql server below 8.1 there is an error
                    // with extended query processing which hinders us from using it.
                    connector.Mediator.RequireReadyForQuery = false;
                    connector.Flush();
                    
                    // Check for errors and/or notifications and do the Right Thing.
                    connector.CheckErrorsAndNotifications();
    
                    
                    // Description...
                    NpgsqlDescribe describe = new NpgsqlDescribe('S', planName);
                
                
                    connector.Describe(describe);
                    
                    connector.Sync();
                    
                    Npgsql.NpgsqlRowDescription returnRowDesc = connector.Mediator.LastRowDescription;
                
                    Int16[] resultFormatCodes;
                    
                    
                    if (returnRowDesc != null)
                    {
                        resultFormatCodes = new Int16[returnRowDesc.NumFields];
                        
                        for (int i=0; i < returnRowDesc.NumFields; i++)
                        {
                            Npgsql.NpgsqlRowDescriptionFieldData returnRowDescData = returnRowDesc[i];
                            
                            
                            if (returnRowDescData.type_info != null && returnRowDescData.type_info.NpgsqlDbType == NpgsqlTypes.NpgsqlDbType.Bytea)
                            {
                            // Binary format
                                resultFormatCodes[i] = (Int16)FormatCode.Binary;
                            }
                            else 
                            // Text Format
                                resultFormatCodes[i] = (Int16)FormatCode.Text;
                        }
                    
                        
                    }
                    else
                        resultFormatCodes = new Int16[]{0};
                    
                    bind = new NpgsqlBind("", planName, new Int16[Parameters.Count], null, resultFormatCodes);
                }    
                catch (IOException e)
                {
                    ClearPoolAndThrowException(e);
                }
                catch
                {
                    // See ExecuteCommand method for a discussion of this.
                    connector.Sync();
                    
                    throw;
                }
                finally
                {
                    connector.ResumeNotificationThread();
                }
                
                
                
            }
        }
Пример #14
0
 public virtual void Bind(NpgsqlConnector context, NpgsqlBind bind)
 {
     throw new InvalidOperationException("Internal Error! " + this);
 }
Пример #15
0
        private void PrepareInternal()
        {
            // Use the extended query parsing...
            planName = m_Connector.NextPlanName();
            String portalName = "";

            preparedCommandText = GetCommandText(true, true);
            NpgsqlParse parse = new NpgsqlParse(planName, preparedCommandText, new Int32[] { });
            NpgsqlDescribe statementDescribe = new NpgsqlDescribeStatement(planName);
            IEnumerable<IServerResponseObject> responseEnum;
            NpgsqlRowDescription returnRowDesc = null;

            // Write Parse, Describe, and Sync messages to the wire.
            m_Connector.Parse(parse);
            m_Connector.Describe(statementDescribe);
            m_Connector.Sync();

            // Tell to mediator what command is being sent.
            m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Parse);

            // Flush and wait for response.
            responseEnum = m_Connector.ProcessBackendResponsesEnum();

            // Look for a NpgsqlRowDescription in the responses, discarding everything else.
            foreach (IServerResponseObject response in responseEnum)
            {
                if (response is NpgsqlRowDescription)
                {
                    returnRowDesc = (NpgsqlRowDescription)response;
                }
                else if (response is IDisposable)
                {
                    (response as IDisposable).Dispose();
                }
            }

            Int16[] resultFormatCodes;

            if (returnRowDesc != null)
            {
                resultFormatCodes = new Int16[returnRowDesc.NumFields];

                for (int i = 0; i < returnRowDesc.NumFields; i++)
                {
                    NpgsqlRowDescription.FieldData returnRowDescData = returnRowDesc[i];

                    if (returnRowDescData.TypeInfo != null)
                    {
                        // Binary format?
                        // PG always defaults to text encoding.  We can fix up the row description
                        // here based on support for binary encoding.  Once this is done,
                        // there is no need to request another row description after Bind.
                        returnRowDescData.FormatCode = returnRowDescData.TypeInfo.SupportsBinaryBackendData ? FormatCode.Binary : FormatCode.Text;
                        resultFormatCodes[i] = (Int16)returnRowDescData.FormatCode;
                    }
                    else
                    {
                        // Text format (default).
                        resultFormatCodes[i] = (Int16)FormatCode.Text;
                    }
                }
            }
            else
            {
                resultFormatCodes = new Int16[] { 0 };
            }

            // Save the row description for use with all future Executes.
            currentRowDescription = returnRowDesc;

            // The Bind and Execute message objects live through multiple Executes.
            // Only Bind changes at all between Executes, which is done in BindParameters().
            bind = new NpgsqlBind(portalName, planName, new Int16[Parameters.Count], null, resultFormatCodes);
            execute = new NpgsqlExecute(portalName, 0);

            prepared = PrepareStatus.Prepared;
        }
 internal void Bind (NpgsqlBind bind)
 {
     CurrentState.Bind(this, bind);
 }
Пример #17
0
 private void UnPrepare()
 {
     if (prepared == PrepareStatus.V3Prepared)
     {
         bind = null;
         execute = null;
         portalDescribeSent = false;
         currentRowDescription = null;
         prepared = PrepareStatus.NeedsPrepare;
     }
     else if (prepared == PrepareStatus.V2Prepared)
     {
         planName = String.Empty;
         prepared = PrepareStatus.NeedsPrepare;
     }
 }