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(); } }
/// <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> /// 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(); }