Example #1
0
		internal NpgsqlTransaction(NpgsqlConnection conn, IsolationLevel isolation)
		{
			_conn = conn;
			_isolation = isolation;

			StringBuilder commandText = new StringBuilder("BEGIN; SET TRANSACTION ISOLATION LEVEL ");

			if (isolation == IsolationLevel.RepeatableRead)
			{
				commandText.Append("REPEATABLE READ");
			}
			else if ((isolation == IsolationLevel.Serializable) ||
				(isolation == IsolationLevel.Snapshot))
			{
				commandText.Append("SERIALIZABLE");
			}
			else
			{
				// Set isolation level default to read committed.
				_isolation = IsolationLevel.ReadCommitted;
				commandText.Append("READ COMMITTED");
			}

			commandText.Append(";");

			NpgsqlCommand command = new NpgsqlCommand(commandText.ToString(), conn.Connector);
			command.ExecuteBlind();
			_conn.Connector.Transaction = this;
		}
Example #2
0
        internal NpgsqlTransaction(NpgsqlConnection conn, IsolationLevel isolation)
        {
            _conn      = conn;
            _isolation = isolation;

            StringBuilder commandText = new StringBuilder("BEGIN; SET TRANSACTION ISOLATION LEVEL ");

            if (isolation == IsolationLevel.RepeatableRead)
            {
                commandText.Append("REPEATABLE READ");
            }
            else if ((isolation == IsolationLevel.Serializable) ||
                     (isolation == IsolationLevel.Snapshot))
            {
                commandText.Append("SERIALIZABLE");
            }
            else
            {
                // Set isolation level default to read committed.
                _isolation = IsolationLevel.ReadCommitted;
                commandText.Append("READ COMMITTED");
            }

            commandText.Append(";");

            NpgsqlCommand command = new NpgsqlCommand(commandText.ToString(), conn.Connector);

            command.ExecuteBlind();
            _conn.Connector.Transaction = this;
        }
 public void PrepareTransaction()
 {
     if (!_prepared)
     {
         NpgsqlConnection connection = GetConnection();
         NpgsqlCommand    command    = new NpgsqlCommand(string.Format("PREPARE TRANSACTION '{0}'", _txName), connection);
         command.ExecuteBlind();
         _prepared = true;
     }
 }
Example #4
0
        /// <summary>
        /// Rolls back a transaction from a pending state.
        /// </summary>
        public override void Rollback()
        {
            CheckDisposed();

            if (_conn == null)
            {
                throw new InvalidOperationException(Exception_NoTransaction);
            }

            NpgsqlCommand command = new NpgsqlCommand("ROLLBACK", _conn.Connector);

            command.ExecuteBlind();
            _conn.Connector.Transaction = null;
            _conn = null;
        }
Example #5
0
 /// <summary>
 /// Command specified upon creation is executed as a non-query.
 /// If CopyStream is set upon creation, it will be flushed to server as copy data, and operation will be finished immediately.
 /// Otherwise the CopyStream member can be used for writing copy data to server and operation finished with a call to End() or Cancel().
 /// </summary>
 public void Start()
 {
     if (_context.CurrentState is NpgsqlReadyState)
     {
         _context.Mediator.CopyStream = _copyStream;
         _cmd.ExecuteBlind();
         _disposeCopyStream = _copyStream == null;
         _copyStream        = _context.Mediator.CopyStream;
         if (_copyStream == null && !(_context.CurrentState is NpgsqlReadyState))
         {
             throw new NpgsqlException("Not a COPY IN query: " + _cmd.CommandText);
         }
     }
     else
     {
         throw new NpgsqlException("Copy can only start in Ready state, not in " + _context.CurrentState);
     }
 }
Example #6
0
        /// <summary>
        /// Creates a transaction save point.
        /// </summary>
        public void Save(String savePointName)
        {
            CheckDisposed();
            if (_conn == null)
            {
                throw new InvalidOperationException(Exception_NoTransaction);
            }
            if (!_conn.Connector.SupportsSavepoint)
            {
                throw new InvalidOperationException(Exception_SavePointNotSupported);
            }

            if (savePointName.Contains(";"))
            {
                throw new InvalidOperationException(Exception_SavePointWithSemicolon);
            }

            NpgsqlCommand command = new NpgsqlCommand("SAVEPOINT " + savePointName, _conn.Connector);

            command.ExecuteBlind();
        }
Example #7
0
		/// <summary>
		/// Creates a transaction save point.
		/// </summary>
		public void Save(String savePointName)
		{
			CheckDisposed();
			if (_conn == null)
			{
				throw new InvalidOperationException(Exception_NoTransaction);
			}
			if (!_conn.Connector.SupportsSavepoint)
			{
				throw new InvalidOperationException(Exception_SavePointNotSupported);
			}

			if (savePointName.Contains(";"))
			{
				throw new InvalidOperationException(Exception_SavePointWithSemicolon);
			}

			NpgsqlCommand command = new NpgsqlCommand("SAVEPOINT " + savePointName, _conn.Connector);
			command.ExecuteBlind();
		}
Example #8
0
		/// <summary>
		/// Rolls back a transaction from a pending state.
		/// </summary>
		public override void Rollback()
		{
			CheckDisposed();

			if (_conn == null)
			{
				throw new InvalidOperationException(Exception_NoTransaction);
			}

			NpgsqlCommand command = new NpgsqlCommand("ROLLBACK", _conn.Connector);
			command.ExecuteBlind();
			_conn.Connector.Transaction = null;
			_conn = null;
		}
		public void PrepareTransaction()
		{
			if (!_prepared)
			{
				NpgsqlConnection connection = GetConnection();
				NpgsqlCommand command = new NpgsqlCommand(string.Format("PREPARE TRANSACTION '{0}'", _txName), connection);
				command.ExecuteBlind();
				_prepared = true;
			}
		}