internal static void ExecuteBlindSuppressTimeout(NpgsqlConnector connector, NpgsqlQuery query) { // Block the notification thread before writing anything to the wire. using (var blocker = connector.BlockNotificationThread()) { // Write the Query message to the wire. connector.Query(query); // Flush, and wait for and discard all responses. connector.ProcessAndDiscardBackendResponses(); } }
/// <summary> /// Special adaptation of ExecuteBlind() that sets statement_timeout. /// This exists to prevent Connector.SetBackendCommandTimeout() from calling Command.ExecuteBlind(), /// which will cause an endless recursive loop. /// </summary> /// <param name="connector"></param> /// <param name="timeout">Timeout in seconds.</param> internal static void ExecuteSetStatementTimeoutBlind(NpgsqlConnector connector, int timeout) { NpgsqlQuery query; // Bypass cpmmand parsing overhead and send command verbatim. query = NpgsqlQuery.Create(connector.BackendProtocolVersion, string.Format("SET statement_timeout = {0}", timeout * 1000)); // Write the Query message to the wire. connector.Query(query); // Flush, and wait for and discard all responses. connector.ProcessAndDiscardBackendResponses(); }
private static void ExecuteBlind(NpgsqlConnector connector, NpgsqlQuery query, int timeout) { // Block the notification thread before writing anything to the wire. using (var blocker = connector.BlockNotificationThread()) { // Set statement timeout as needed. connector.SetBackendCommandTimeout(timeout); // Write the Query message to the wire. connector.Query(query); // Flush, and wait for and discard all responses. connector.ProcessAndDiscardBackendResponses(); } }
public override IEnumerable <IServerResponseObject> QueryEnum(NpgsqlConnector context, NpgsqlCommand command) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "QueryEnum"); //String commandText = command.GetCommandText(); //NpgsqlEventLog.LogMsg(resman, "Log_QuerySent", LogLevel.Debug, commandText); // Send the query request to backend. NpgsqlQuery query = new NpgsqlQuery(command, context.BackendProtocolVersion); query.WriteToStream(context.Stream); context.Stream.Flush(); return(ProcessBackendResponsesEnum(context, false)); }
/// <summary> /// Slightly optimised version of ExecuteNonQuery() for internal use in cases where the number /// of affected rows is of no interest. /// This function must not be called with a query that returns result rows, after calling Prepare(), or. /// with a query that requires parameter substitution of any kind. /// </summary> internal void ExecuteBlind() { NpgsqlQuery query; // Bypass cpmmand parsing overhead and send commandText verbatim. query = new NpgsqlQuery(m_Connector, commandText); // Block the notification thread before writing anything to the wire. using (var blocker = m_Connector.BlockNotificationThread()) { // Write the Query message to the wire. m_Connector.Query(query); // Flush, and wait for and discard all responses. m_Connector.ProcessAndDiscardBackendResponses(); } }
public override IEnumerable<IServerResponseObject> QueryEnum(NpgsqlConnector context, NpgsqlCommand command) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "QueryEnum"); //String commandText = command.GetCommandText(); //NpgsqlEventLog.LogMsg(resman, "Log_QuerySent", LogLevel.Debug, commandText); // Send the query request to backend. NpgsqlQuery query = new NpgsqlQuery(command, context.BackendProtocolVersion); query.WriteToStream(context.Stream); context.Stream.Flush(); return ProcessBackendResponsesEnum(context); }
public override void Query(NpgsqlConnector context, NpgsqlCommand command) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Query"); //String commandText = command.GetCommandText(); //NpgsqlEventLog.LogMsg(resman, "Log_QuerySent", LogLevel.Debug, commandText); // Send the query request to backend. NpgsqlQuery query = new NpgsqlQuery(command, context.BackendProtocolVersion); query.WriteToStream(context.Stream, context.Encoding); context.Stream.Flush(); ProcessBackendResponses(context); }
/// <summary> /// Special adaptation of ExecuteBlind() that sets statement_timeout. /// This exists to prevent Connector.SetBackendCommandTimeout() from calling Command.ExecuteBlind(), /// which will cause an endless recursive loop. /// </summary> /// <param name="connector"></param> /// <param name="timeout">Timeout in seconds.</param> internal static void ExecuteSetStatementTimeoutBlind(NpgsqlConnector connector, int timeout) { NpgsqlQuery query; // Optimize for a few common timeout values. switch (timeout) { case 10: query = NpgsqlQuery.SetStmtTimeout10Sec; break; case 20: query = NpgsqlQuery.SetStmtTimeout20Sec; break; case 30: query = NpgsqlQuery.SetStmtTimeout30Sec; break; case 60: query = NpgsqlQuery.SetStmtTimeout60Sec; break; case 90: query = NpgsqlQuery.SetStmtTimeout90Sec; break; case 120: query = NpgsqlQuery.SetStmtTimeout120Sec; break; default: query = new NpgsqlQuery(string.Format("SET statement_timeout = {0}", timeout * 1000)); break; } // Write the Query message to the wire. connector.Query(query); // Flush, and wait for and discard all responses. connector.ProcessAndDiscardBackendResponses(); }
public override void Query( NpgsqlConnector context, NpgsqlCommand command ) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Query"); //String commandText = command.GetCommandText(); //NpgsqlEventLog.LogMsg(resman, "Log_QuerySent", LogLevel.Debug, commandText); // Send the query request to backend. NpgsqlQuery query = new NpgsqlQuery(command, context.BackendProtocolVersion); query.WriteToStream(context.Stream, context.Encoding); context.Stream.Flush(); ProcessBackendResponses(context); }
internal ForwardsOnlyDataReader GetReader(CommandBehavior cb) { CheckConnectionState(); // reset any responses just before getting new ones Connector.Mediator.ResetResponses(); // Set command timeout. m_Connector.Mediator.CommandTimeout = CommandTimeout; // Block the notification thread before writing anything to the wire. using (m_Connector.BlockNotificationThread()) { IEnumerable<IServerResponseObject> responseEnum; ForwardsOnlyDataReader reader; if (prepared == PrepareStatus.NeedsPrepare) { PrepareInternal(); } if (prepared == PrepareStatus.NotPrepared || prepared == PrepareStatus.V2Prepared) { NpgsqlQuery query; query = new NpgsqlQuery(m_Connector, GetCommandText()); // Write the Query message to the wire. m_Connector.Query(query); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); if ( type == CommandType.StoredProcedure && reader.FieldCount == 1 && reader.GetDataTypeName(0) == "refcursor" ) { // When a function returns a sole column of refcursor, transparently // FETCH ALL from every such cursor and return those results. StringWriter sw = new StringWriter(); string queryText; while (reader.Read()) { sw.WriteLine("FETCH ALL FROM \"{0}\";", reader.GetString(0)); } reader.Dispose(); queryText = sw.ToString(); if (queryText == "") { queryText = ";"; } // Passthrough the commandtimeout to the inner command, so user can also control its timeout. // TODO: Check if there is a better way to handle that. query = new NpgsqlQuery(m_Connector, queryText); // Write the Query message to the wire. m_Connector.Query(query); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); } } else { bool sendPortalDescribe = ! portalDescribeSent; // Update the Bind object with current parameter data as needed. BindParameters(); // Write the Bind message to the wire. m_Connector.Bind(bind); if (sendPortalDescribe) { NpgsqlDescribe portalDescribe = new NpgsqlDescribePortal(bind.PortalName); // Write a Describe message to the wire. m_Connector.Describe(portalDescribe); portalDescribeSent = true; } // Finally, write the Execute and Sync messages to the wire. m_Connector.Execute(execute); m_Connector.Sync(); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader, possibly with a saved row description. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread(), true, currentRowDescription ); if (sendPortalDescribe) { // We sent a Describe message. If the query produces a result set, // PG sent a row description, and the reader has now found it, currentRowDescription = reader.CurrentDescription; } } return reader; } }
internal void Query(NpgsqlQuery query) { CurrentState.Query(this, query); }
public virtual void Query(NpgsqlConnector context, NpgsqlQuery query) { throw new InvalidOperationException("Internal Error! " + this); }
internal void ExecuteBlind(NpgsqlQuery query) { // Block the notification thread before writing anything to the wire. using (BlockNotificationThread()) { // Set statement timeout as needed. SetBackendCommandTimeout(20); // Write the Query message to the wire. Query(query); // Flush, and wait for and discard all responses. ProcessAndDiscardBackendResponses(); } }
public override void Query(NpgsqlConnector context, NpgsqlQuery query) { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Query"); query.WriteToStream(context.Stream); }
internal void Query(NpgsqlQuery query) { if (_log.IsDebugEnabled) _log.Debug("Sending query: " + query); query.WriteToStream(Stream); State = NpgsqlState.Executing; }
/// <summary> /// Internal query shortcut for use in cases where the number /// of affected rows is of no interest. /// </summary> internal static void ExecuteBlind(NpgsqlConnector connector, string command, int timeout = 20) { // Bypass cpmmand parsing overhead and send command verbatim. ExecuteBlind(connector, NpgsqlQuery.Create(connector.BackendProtocolVersion, command), timeout); }
public virtual void Query(NpgsqlConnector context, NpgsqlQuery query) { throw new InvalidOperationException("¬нутренн¤¤ ќшибка! " + this); }
internal ForwardsOnlyDataReader GetReader(CommandBehavior cb) { CheckConnectionState(); // Block the notification thread before writing anything to the wire. using (m_Connector.BlockNotificationThread()) { IEnumerable<IServerResponseObject> responseEnum; ForwardsOnlyDataReader reader; m_Connector.SetBackendCommandTimeout(CommandTimeout); if (prepared == PrepareStatus.NeedsPrepare) { PrepareInternal(); } if (prepared == PrepareStatus.NotPrepared) { NpgsqlQuery query; byte[] commandText = GetCommandText(); query = new NpgsqlQuery(commandText); // Write the Query message to the wire. m_Connector.Query(query); // Tell to mediator what command is being sent. if (prepared == PrepareStatus.NotPrepared) { m_Connector.Mediator.SetSqlSent(commandText, NpgsqlMediator.SQLSentType.Simple); } else { m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Execute); } // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); if ( commandType == CommandType.StoredProcedure && reader.FieldCount == 1 && reader.GetDataTypeName(0) == "refcursor" ) { // When a function returns a sole column of refcursor, transparently // FETCH ALL from every such cursor and return those results. StringWriter sw = new StringWriter(); string queryText; while (reader.Read()) { sw.WriteLine("FETCH ALL FROM \"{0}\";", reader.GetString(0)); } reader.Dispose(); queryText = sw.ToString(); if (queryText == "") { queryText = ";"; } // Passthrough the commandtimeout to the inner command, so user can also control its timeout. // TODO: Check if there is a better way to handle that. query = new NpgsqlQuery(queryText); // Write the Query message to the wire. m_Connector.Query(query); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); } } else { // Update the Bind object with current parameter data as needed. BindParameters(); // Write the Bind, Execute, and Sync message to the wire. m_Connector.Bind(bind); m_Connector.Execute(execute); m_Connector.Sync(); // Tell to mediator what command is being sent. m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Execute); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader, possibly with a saved row description from Prepare(). reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread(), true, currentRowDescription ); } return reader; } }
internal ForwardsOnlyDataReader GetReader(CommandBehavior cb) { CheckConnectionState(); // Block the notification thread before writing anything to the wire. using (m_Connector.BlockNotificationThread()) { IEnumerable <IServerResponseObject> responseEnum; ForwardsOnlyDataReader reader; m_Connector.SetBackendCommandTimeout(CommandTimeout); if (prepared == PrepareStatus.NeedsPrepare) { PrepareInternal(); } if (prepared == PrepareStatus.NotPrepared || prepared == PrepareStatus.V2Prepared) { NpgsqlQuery query; byte[] commandText = GetCommandText(); query = NpgsqlQuery.Create(m_Connector.BackendProtocolVersion, commandText); // Write the Query message to the wire. m_Connector.Query(query); // Tell to mediator what command is being sent. if (prepared == PrepareStatus.NotPrepared) { m_Connector.Mediator.SetSqlSent(commandText, NpgsqlMediator.SQLSentType.Simple); } else { m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Execute); } // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); if ( commandType == CommandType.StoredProcedure && reader.FieldCount == 1 && reader.GetDataTypeName(0) == "refcursor" ) { // When a function returns a sole column of refcursor, transparently // FETCH ALL from every such cursor and return those results. StringWriter sw = new StringWriter(); string queryText; while (reader.Read()) { sw.WriteLine("FETCH ALL FROM \"{0}\";", reader.GetString(0)); } reader.Dispose(); queryText = sw.ToString(); if (queryText == "") { queryText = ";"; } // Passthrough the commandtimeout to the inner command, so user can also control its timeout. // TODO: Check if there is a better way to handle that. query = NpgsqlQuery.Create(m_Connector.BackendProtocolVersion, queryText); // Write the Query message to the wire. m_Connector.Query(query); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader. reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread() ); } } else { // Update the Bind object with current parameter data as needed. BindParameters(); // Write the Bind, Execute, and Sync message to the wire. m_Connector.Bind(bind); m_Connector.Execute(execute); m_Connector.Sync(); // Tell to mediator what command is being sent. m_Connector.Mediator.SetSqlSent(preparedCommandText, NpgsqlMediator.SQLSentType.Execute); // Flush and wait for responses. responseEnum = m_Connector.ProcessBackendResponsesEnum(); // Construct the return reader, possibly with a saved row description from Prepare(). reader = new ForwardsOnlyDataReader( responseEnum, cb, this, m_Connector.BlockNotificationThread(), true, currentRowDescription ); } return(reader); } }
/// <summary> /// Special adaptation of ExecuteBlind() that sets statement_timeout. /// This exists to prevent Connector.SetBackendCommandTimeout() from calling Command.ExecuteBlind(), /// which will cause an endless recursive loop. /// </summary> /// <param name="connector"></param> /// <param name="timeout">Timeout in seconds.</param> internal static void ExecuteSetStatementTimeoutBlind(NpgsqlConnector connector, int timeout) { NpgsqlQuery query; // Optimize for a few common timeout values. switch (timeout) { case 10 : query = NpgsqlQuery.SetStmtTimeout10Sec; break; case 20 : query = NpgsqlQuery.SetStmtTimeout20Sec; break; case 30 : query = NpgsqlQuery.SetStmtTimeout30Sec; break; case 60 : query = NpgsqlQuery.SetStmtTimeout60Sec; break; case 90 : query = NpgsqlQuery.SetStmtTimeout90Sec; break; case 120 : query = NpgsqlQuery.SetStmtTimeout120Sec; break; default : query = new NpgsqlQuery(string.Format("SET statement_timeout = {0}", timeout * 1000)); break; } // Write the Query message to the wire. connector.Query(query); // Flush, and wait for and discard all responses. connector.ProcessAndDiscardBackendResponses(); }
/// <summary> /// Slightly optimised version of ExecuteNonQuery() for internal ues in cases where the number /// of affected rows is of no interest. /// This function must not be called with a query that returns result rows, or after calling Prepare(). /// </summary> internal void ExecuteBlind() { if (prepared == PrepareStatus.V2Prepared || prepared == PrepareStatus.V3Prepared) { throw new InvalidOperationException("Cannot call ExecuteBlind() on a prepared command"); } NpgsqlQuery query; query = new NpgsqlQuery(m_Connector, GetCommandText()); // Block the notification thread before writing anything to the wire. using (var blocker = m_Connector.BlockNotificationThread()) { // Write the Query message to the wire. m_Connector.Query(query); // Flush, and wait for and discard all responses. m_Connector.ProcessAndDiscardBackendResponses(); } }