Esempio n. 1
0
 void RaiseEvent(EventHandler <PrepareEventArgs> eh, PrepareStatus status)
 {
     if (eh != null)
     {
         eh(this, new PrepareEventArgs(status, this.prepareCaller));
     }
 }
Esempio n. 2
0
    IEnumerator RaiseEvent(EventHandler <PrepareEventArgs> eh, PrepareStatus status, float delay)
    {
        yield return(new WaitForSeconds(delay));

        if (eh != null)
        {
            eh(this, new PrepareEventArgs(status, this.prepareCaller));
        }
    }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Npgsql.NpgsqlCommand">NpgsqlCommand</see> class with the text of the query, a <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see>, and the <see cref="Npgsql.NpgsqlTransaction">NpgsqlTransaction</see>.
        /// </summary>
        /// <param name="cmdText">The text of the query.</param>
        /// <param name="connection">A <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see> that represents the connection to a PostgreSQL server.</param>
        /// <param name="transaction">The <see cref="Npgsql.NpgsqlTransaction">NpgsqlTransaction</see> in which the <see cref="Npgsql.NpgsqlCommand">NpgsqlCommand</see> executes.</param>
        public NpgsqlCommand(String cmdText, NpgsqlConnection connection, NpgsqlTransaction transaction)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);

            planName        = String.Empty;
            commandText     = cmdText;
            this.connection = connection;

            if (this.connection != null)
            {
                this.m_Connector = connection.Connector;

                if (m_Connector != null && m_Connector.AlwaysPrepare)
                {
                    CommandTimeout = m_Connector.DefaultCommandTimeout;
                    prepared       = PrepareStatus.NeedsPrepare;
                }
            }

            commandType      = CommandType.Text;
            this.Transaction = transaction;

            SetCommandTimeout();
        }
Esempio n. 4
0
 IEnumerator RaiseEvent(EventHandler<PrepareEventArgs> eh, PrepareStatus status, float delay)
 {
     yield return new WaitForSeconds(delay);
     if (eh != null)
     {
         eh(this, new PrepareEventArgs(status, this.prepareCaller));
     }
 }
Esempio n. 5
0
 void RaiseEvent(EventHandler<PrepareEventArgs> eh, PrepareStatus status)
 {
     if (eh != null)
     {
         eh(this, new PrepareEventArgs(status, this.prepareCaller));
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Npgsql.NpgsqlCommand">NpgsqlCommand</see> class with the text of the query, a <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see>, and the <see cref="Npgsql.NpgsqlTransaction">NpgsqlTransaction</see>.
        /// </summary>
        /// <param name="cmdText">The text of the query.</param>
        /// <param name="connection">A <see cref="Npgsql.NpgsqlConnection">NpgsqlConnection</see> that represents the connection to a PostgreSQL server.</param>
        /// <param name="transaction">The <see cref="Npgsql.NpgsqlTransaction">NpgsqlTransaction</see> in which the <see cref="Npgsql.NpgsqlCommand">NpgsqlCommand</see> executes.</param>
        public NpgsqlCommand(String cmdText, NpgsqlConnection connection, NpgsqlTransaction transaction)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);

            planName = String.Empty;
            commandText = cmdText;
            this.connection = connection;

            if (this.connection != null)
            {
                this.m_Connector = connection.Connector;

                if (m_Connector != null && m_Connector.AlwaysPrepare)
                {
                    CommandTimeout = m_Connector.DefaultCommandTimeout;
                    prepared = PrepareStatus.NeedsPrepare;
                }
            }

            commandType = CommandType.Text;
            this.Transaction = transaction;

            SetCommandTimeout();
        }
Esempio n. 7
0
        void UnPrepare()
        {
            if (_prepared == PrepareStatus.Prepared)
            {
                _connector.ExecuteBlind("DEALLOCATE " + _planName);
                _currentRowDescription = null;
                _prepared = PrepareStatus.NeedsPrepare;
            }

            _preparedCommandText = null;
        }
Esempio n. 8
0
        void PrepareInternal()
        {
            // Use the extended query parsing...
            _planName = _connector.NextPlanName();
            const string portalName = "";

            _preparedCommandText = GetCommandText(true);
            NpgsqlRowDescription returnRowDesc = null;
            ParameterDescriptionResponse parameterDescription = null;


            var numInputParameters = 0;
            for (var i = 0; i < _parameters.Count; i++)
            {
                if (_parameters[i].IsInputDirection)
                {
                    numInputParameters++;
                }
            }

            var parameterTypeOIDs = new int[numInputParameters];

            for (int i = 0, j = 0; i < _parameters.Count; i++)
            {
                if (_parameters[i].IsInputDirection)
                {
                    parameterTypeOIDs[j++] = _parameters[i].TypeInfo.NpgsqlDbType == NpgsqlDbType.Unknown ? 0 : _connector.OidToNameMapping[_parameters[i].TypeInfo.Name].OID;
                }
            }

            // Write Parse, Describe, and Sync messages to the wire.
            _connector.SendParse(_planName, _preparedCommandText, parameterTypeOIDs);
            _connector.SendDescribeStatement(_planName);
            _connector.SendSync();

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

            // Look for ParameterDescriptionResponse, NpgsqlRowDescription in the responses, discarding everything else.
            while (true)
            {
                var msg = _connector.ReadMessage();
                if (msg is ReadyForQueryMsg) {
                    break;
                }
                var asParameterDescription = msg as ParameterDescriptionResponse;
                if (asParameterDescription != null)
                {
                    parameterDescription = asParameterDescription;
                    continue;
                }
                var asRowDesc = msg as NpgsqlRowDescription;
                if (asRowDesc != null)
                {
                    returnRowDesc = asRowDesc;
                    continue;
                }
                var asDisposable = msg as IDisposable;
                if (asDisposable != null)
                {
                    asDisposable.Dispose();
                }
            }

            if (parameterDescription != null)
            {
                if (parameterDescription.TypeOIDs.Length != numInputParameters)
                {
                    throw new InvalidOperationException("Wrong number of parameters. Got " + numInputParameters + " but expected " + parameterDescription.TypeOIDs.Length + ".");
                }

                for (int i = 0, j = 0; j < numInputParameters; i++)
                {
                    if (_parameters[i].IsInputDirection)
                    {
                        _parameters[i].SetTypeOID(parameterDescription.TypeOIDs[j++], _connector.NativeToBackendTypeConverterOptions);
                    }
                }
            }

            if (returnRowDesc != null)
            {
                _resultFormatCodes = new short[returnRowDesc.NumFields];

                for (var i = 0; i < returnRowDesc.NumFields; i++)
                {
                    var 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] = (short)returnRowDescData.FormatCode;
                    }
                    else
                    {
                        // Text format (default).
                        _resultFormatCodes[i] = (short)FormatCode.Text;
                    }
                }
            }
            else
            {
                _resultFormatCodes = new short[] { 0 };
            }

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

            _prepared = PrepareStatus.Prepared;
        }
Esempio n. 9
0
 void OnConnectionStateChange(object sender, StateChangeEventArgs stateChangeEventArgs)
 {
     switch (stateChangeEventArgs.CurrentState)
     {
         case ConnectionState.Broken:
         case ConnectionState.Closed:
             _prepared = PrepareStatus.NotPrepared;
             break;
         case ConnectionState.Open:
             switch (stateChangeEventArgs.OriginalState)
             {
                 case ConnectionState.Closed:
                 case ConnectionState.Broken:
                     _prepared = _connector != null && _connector.AlwaysPrepare ? PrepareStatus.NeedsPrepare : PrepareStatus.NotPrepared;
                     break;
             }
             break;
         case ConnectionState.Connecting:
         case ConnectionState.Executing:
         case ConnectionState.Fetching:
             return;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Esempio n. 10
0
 public PrepareEventArgs(PrepareStatus status, Caller caller) : base()
 {
     this.status = status;
     this.caller = caller;
 }
Esempio n. 11
0
 public PrepareEventArgs(PrepareStatus status, Caller caller) : base()
 {
        this.status = status;
        this.caller = caller;
 }
Esempio n. 12
0
        void PrepareInternal()
        {
            // Use the extended query parsing...
            _planName = _connector.NextPlanName();
            const string portalName = "";

            _preparedCommandText = GetCommandText(true);
            var parse = new NpgsqlParse(_planName, _preparedCommandText, new int[] { });
            var statementDescribe = new NpgsqlDescribeStatement(_planName);
            NpgsqlRowDescription returnRowDesc = null;

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

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

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

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

            short[] resultFormatCodes;

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

                for (var i = 0; i < returnRowDesc.NumFields; i++)
                {
                    var 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] = (short)returnRowDescData.FormatCode;
                    }
                    else
                    {
                        // Text format (default).
                        resultFormatCodes[i] = (short)FormatCode.Text;
                    }
                }
            }
            else
            {
                resultFormatCodes = new short[] { 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;
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NpgsqlCommand">NpgsqlCommand</see> class with the text of the query, a <see cref="NpgsqlConnection">NpgsqlConnection</see>, and the <see cref="NpgsqlTransaction">NpgsqlTransaction</see>.
        /// </summary>
        /// <param name="cmdText">The text of the query.</param>
        /// <param name="connection">A <see cref="NpgsqlConnection">NpgsqlConnection</see> that represents the connection to a PostgreSQL server.</param>
        /// <param name="transaction">The <see cref="NpgsqlTransaction">NpgsqlTransaction</see> in which the <see cref="NpgsqlCommand">NpgsqlCommand</see> executes.</param>
        public NpgsqlCommand(String cmdText, NpgsqlConnection connection, NpgsqlTransaction transaction)
        {
            _planName = String.Empty;
            _commandText = cmdText;
            _connection = connection;

            if (_connection != null)
            {
                _connector = connection.Connector;

                if (_connector != null && _connector.AlwaysPrepare)
                {
                    CommandTimeout = _connector.DefaultCommandTimeout;
                    _prepared = PrepareStatus.NeedsPrepare;
                }
            }

            CommandType = CommandType.Text;
            Transaction = transaction;

            SetCommandTimeout();
        }
Esempio n. 14
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;
            }
        }
Esempio n. 15
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;
     }
 }