public static void ExecuteProcedureNonQuery(string spName, FbParameter[] parameters, FbTransactionBehavior tranBeh)
 {
     OpenConnection();
     if ((!storedProcs.ContainsKey(spName))
         || (storedProcs[spName].Parameters.Count != parameters.Length))
     {
         string sql = "";
         for (int i = 0; i < parameters.Length; i++)
             sql += ",?";
         sql = "EXECUTE PROCEDURE " + spName + "(" + sql.Substring(1) + ")";
         FbCommand commandProcedure = new FbCommand(sql, mConnection);
         commandProcedure.CommandType = CommandType.StoredProcedure;
         commandProcedure.Parameters.AddRange(parameters);
         storedProcs[spName] = commandProcedure;
     }
     else
     {
         for (int i = 0; i < parameters.Length; i++)
             storedProcs[spName].Parameters[i].Value = parameters[i].Value;
     }
     FbTransactionOptions transactionOptions = new FbTransactionOptions();
     transactionOptions.TransactionBehavior = tranBeh;
     storedProcs[spName].Transaction = mConnection.BeginTransaction(transactionOptions);
     storedProcs[spName].ExecuteNonQuery();
     storedProcs[spName].Transaction.Commit();
 }
        public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName)
        {
            EnsureActiveTransaction();

            try
            {
                _activeTransaction = new FbTransaction(_owningConnection, IsolationLevel.Unspecified);
                _activeTransaction.BeginTransaction(options);

                if (transactionName != null)
                {
                    _activeTransaction.Save(transactionName);
                }
            }
            catch (IscException ex)
            {
                DisposeTransaction();
                throw new FbException(ex.Message, ex);
            }

            return(_activeTransaction);
        }
Exemple #3
0
        public async Task <FbTransaction> BeginTransactionAsync(FbTransactionOptions options, string transactionName, CancellationToken cancellationToken = default)
        {
            EnsureActiveTransaction();

            try
            {
                _activeTransaction = new FbTransaction(_owningConnection, IsolationLevel.Unspecified);
                await _activeTransaction.BeginTransactionAsync(options, cancellationToken).ConfigureAwait(false);

                if (transactionName != null)
                {
                    _activeTransaction.Save(transactionName);
                }
            }
            catch (IscException ex)
            {
                await DisposeTransactionAsync(cancellationToken).ConfigureAwait(false);

                throw FbException.Create(ex);
            }

            return(_activeTransaction);
        }
Exemple #4
0
        public async Task <FbTransaction> BeginTransaction(FbTransactionOptions options, string transactionName, AsyncWrappingCommonArgs async)
        {
            EnsureActiveTransaction();

            try
            {
                _activeTransaction = new FbTransaction(_owningConnection, IsolationLevel.Unspecified);
                await _activeTransaction.BeginTransaction(options, async).ConfigureAwait(false);

                if (transactionName != null)
                {
                    _activeTransaction.Save(transactionName);
                }
            }
            catch (IscException ex)
            {
                await DisposeTransaction(async).ConfigureAwait(false);

                throw new FbException(ex.Message, ex);
            }

            return(_activeTransaction);
        }
        private TransactionParameterBuffer BuildTpb()
        {
            FbTransactionOptions options = new FbTransactionOptions();

            options.WaitTimeout         = null;
            options.TransactionBehavior = FbTransactionBehavior.Write;

            options.TransactionBehavior |= FbTransactionBehavior.Wait;

            /* Isolation level */
            switch (this.isolationLevel)
            {
            case IsolationLevel.Serializable:
                options.TransactionBehavior |= FbTransactionBehavior.Consistency;
                break;

            case IsolationLevel.RepeatableRead:
            case IsolationLevel.Snapshot:
                options.TransactionBehavior |= FbTransactionBehavior.Concurrency;
                break;

            case IsolationLevel.ReadUncommitted:
                options.TransactionBehavior |= FbTransactionBehavior.ReadCommitted;
                options.TransactionBehavior |= FbTransactionBehavior.RecVersion;
                break;

            case IsolationLevel.ReadCommitted:
            default:
                options.TransactionBehavior |= FbTransactionBehavior.ReadCommitted;
                options.TransactionBehavior |= FbTransactionBehavior.NoRecVersion;
                break;
            }

            // just empty FbTransactionOptionsValues struct
            return(this.BuildTpb(options));
        }
        private TransactionParameterBuffer BuildTpb()
        {
            FbTransactionOptions options = new FbTransactionOptions();
            options.WaitTimeout = null;
            options.TransactionBehavior = FbTransactionBehavior.Write;

            options.TransactionBehavior |= FbTransactionBehavior.Wait;

            /* Isolation level */
            switch (this.isolationLevel)
            {
                case IsolationLevel.Serializable:
                    options.TransactionBehavior |= FbTransactionBehavior.Consistency;
                    break;

                case IsolationLevel.RepeatableRead:
				case IsolationLevel.Snapshot:
                    options.TransactionBehavior |= FbTransactionBehavior.Concurrency;
                    break;

                case IsolationLevel.ReadUncommitted:
                    options.TransactionBehavior |= FbTransactionBehavior.ReadCommitted;
                    options.TransactionBehavior |= FbTransactionBehavior.RecVersion;
                    break;

                case IsolationLevel.ReadCommitted:
                default:
                    options.TransactionBehavior |= FbTransactionBehavior.ReadCommitted;
                    options.TransactionBehavior |= FbTransactionBehavior.NoRecVersion;
                    break;
            }

            // just empty FbTransactionOptionsValues struct
            return this.BuildTpb(options);
        }
 internal void BeginTransaction(FbTransactionOptions options)
 {
     lock (this)
     {
         try
         {
             IDatabase database = this.connection.InnerConnection.Database;
             this.transaction = database.BeginTransaction(this.BuildTpb(options));
         }
         catch (IscException ex)
         {
             throw new FbException(ex.Message, ex);
         }
     }
 }
		private TransactionParameterBuffer BuildTpb()
		{
			FbTransactionOptions options = new FbTransactionOptions();
			options.WaitTimeout = null;
			options.TransactionBehavior = FbTransactionBehavior.Write;

			options.TransactionBehavior |= FbTransactionBehavior.NoWait;

			switch (_isolationLevel)
			{
				case IsolationLevel.Serializable:
					options.TransactionBehavior |= FbTransactionBehavior.Consistency;
					break;

				case IsolationLevel.RepeatableRead:
				case IsolationLevel.Snapshot:
					options.TransactionBehavior |= FbTransactionBehavior.Concurrency;
					break;

				case IsolationLevel.ReadCommitted:
				case IsolationLevel.ReadUncommitted:
				default:
					options.TransactionBehavior |= FbTransactionBehavior.ReadCommitted;
					options.TransactionBehavior |= FbTransactionBehavior.RecVersion;
					break;
			}

			return BuildTpb(options);
		}
Exemple #9
0
 public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName) => BeginTransactionImpl(options, transactionName, new AsyncWrappingCommonArgs(false)).GetAwaiter().GetResult();
Exemple #10
0
 public FbTransaction BeginTransaction(FbTransactionOptions options)
 {
     return(BeginTransaction(options, null));
 }
        public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName)
        {
			this.CheckClosed();

            return this.innerConnection.BeginTransaction(options, transactionName);
        }
        private static TransactionParameterBuffer BuildTpb(FbTransactionOptions options)
        {
            var tpb = new TransactionParameterBuffer();

            tpb.Append(IscCodes.isc_tpb_version3);

            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Consistency))
            {
                tpb.Append(IscCodes.isc_tpb_consistency);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Concurrency))
            {
                tpb.Append(IscCodes.isc_tpb_concurrency);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Wait))
            {
                tpb.Append(IscCodes.isc_tpb_wait);
                if (options.WaitTimeoutTPBValue.HasValue)
                {
                    tpb.Append(IscCodes.isc_tpb_lock_timeout, (short)options.WaitTimeoutTPBValue);
                }
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.NoWait))
            {
                tpb.Append(IscCodes.isc_tpb_nowait);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Read))
            {
                tpb.Append(IscCodes.isc_tpb_read);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Write))
            {
                tpb.Append(IscCodes.isc_tpb_write);
            }
            foreach (var table in options.LockTables)
            {
                int lockType;
                if (table.Value.HasFlag(FbTransactionBehavior.LockRead))
                {
                    lockType = IscCodes.isc_tpb_lock_read;
                }
                else if (table.Value.HasFlag(FbTransactionBehavior.LockWrite))
                {
                    lockType = IscCodes.isc_tpb_lock_write;
                }
                else
                {
                    throw new ArgumentException("Must specify either LockRead or LockWrite.");
                }
                tpb.Append(lockType, table.Key);

                int?lockBehavior = null;
                if (table.Value.HasFlag(FbTransactionBehavior.Exclusive))
                {
                    lockBehavior = IscCodes.isc_tpb_exclusive;
                }
                else if (table.Value.HasFlag(FbTransactionBehavior.Protected))
                {
                    lockBehavior = IscCodes.isc_tpb_protected;
                }
                else if (table.Value.HasFlag(FbTransactionBehavior.Shared))
                {
                    lockBehavior = IscCodes.isc_tpb_shared;
                }
                if (lockBehavior.HasValue)
                {
                    tpb.Append((int)lockBehavior);
                }
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.ReadCommitted))
            {
                tpb.Append(IscCodes.isc_tpb_read_committed);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.Autocommit))
            {
                tpb.Append(IscCodes.isc_tpb_autocommit);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.RecVersion))
            {
                tpb.Append(IscCodes.isc_tpb_rec_version);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.NoRecVersion))
            {
                tpb.Append(IscCodes.isc_tpb_no_rec_version);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.RestartRequests))
            {
                tpb.Append(IscCodes.isc_tpb_restart_requests);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.NoAutoUndo))
            {
                tpb.Append(IscCodes.isc_tpb_no_auto_undo);
            }
            if (options.TransactionBehavior.HasFlag(FbTransactionBehavior.ReadConsistency))
            {
                tpb.Append(IscCodes.isc_tpb_read_consistency);
            }

            return(tpb);
        }
Exemple #13
0
 public Task <FbTransaction> BeginTransactionAsync(FbTransactionOptions options, CancellationToken cancellationToken = default) => BeginTransactionAsync(options, null, cancellationToken);
Exemple #14
0
 public FbTransaction BeginTransaction(FbTransactionOptions options) => BeginTransaction(options, null);
        public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName)
        {
            lock (this)
            {
                if (this.HasActiveTransaction)
                {
                    throw new InvalidOperationException("A transaction is currently active. Parallel transactions are not supported.");
                }

                try
                {
                    this.activeTransaction = new FbTransaction(
                        this.owningConnection, IsolationLevel.Unspecified);

                    this.activeTransaction.BeginTransaction(options);

                    if (transactionName != null)
                    {
                        this.activeTransaction.Save(transactionName);
                    }
                }
                catch (IscException ex)
                {
                    throw new FbException(ex.Message, ex);
                }
            }

            return this.activeTransaction;
        }
Exemple #16
0
        internal Task <FbTransaction> BeginTransactionImpl(FbTransactionOptions options, string transactionName, AsyncWrappingCommonArgs async)
        {
            CheckClosed();

            return(_innerConnection.BeginTransaction(options, transactionName, async));
        }
Exemple #17
0
 public Task <FbTransaction> BeginTransactionAsync(FbTransactionOptions options, string transactionName, CancellationToken cancellationToken = default) => BeginTransactionImpl(options, transactionName, new AsyncWrappingCommonArgs(true, cancellationToken));
        private TransactionParameterBuffer BuildTpb(FbTransactionOptions options)
		{
			TransactionParameterBuffer tpb = new TransactionParameterBuffer();

			tpb.Append(IscCodes.isc_tpb_version3);

            if ((options.TransactionBehavior & FbTransactionBehavior.Consistency) == FbTransactionBehavior.Consistency)
            {
                tpb.Append(IscCodes.isc_tpb_consistency);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.Concurrency) == FbTransactionBehavior.Concurrency)
            {
                tpb.Append(IscCodes.isc_tpb_concurrency);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.Wait) == FbTransactionBehavior.Wait)
            {
                tpb.Append(IscCodes.isc_tpb_wait);
                if (options.WaitTimeout.HasValue)
                {
                    tpb.Append(IscCodes.isc_tpb_lock_timeout, (short)options.WaitTimeout);
                }
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.NoWait) == FbTransactionBehavior.NoWait)
            {
                tpb.Append(IscCodes.isc_tpb_nowait);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.Read) == FbTransactionBehavior.Read)
            {
                tpb.Append(IscCodes.isc_tpb_read);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.Write) == FbTransactionBehavior.Write)
            {
                tpb.Append(IscCodes.isc_tpb_write);
            }
			foreach (var table in options.LockTables)
			{
				int lockType;
				if ((table.Value & FbTransactionBehavior.LockRead) == FbTransactionBehavior.LockRead)
				{
					lockType = IscCodes.isc_tpb_lock_read;
				}
				else if ((table.Value & FbTransactionBehavior.LockWrite) == FbTransactionBehavior.LockWrite)
				{
					lockType = IscCodes.isc_tpb_lock_write;
				}
				else
				{
					throw new ArgumentException("Must specify either LockRead or LockWrite.");
				}				
				tpb.Append(lockType, table.Key);

				int? lockBehavior = null;
				if ((table.Value & FbTransactionBehavior.Exclusive) == FbTransactionBehavior.Exclusive)
				{
					lockBehavior = IscCodes.isc_tpb_exclusive;
				}
				else if ((table.Value & FbTransactionBehavior.Protected) == FbTransactionBehavior.Protected)
				{
					lockBehavior = IscCodes.isc_tpb_protected;
				}
				else if ((table.Value & FbTransactionBehavior.Shared) == FbTransactionBehavior.Shared)
				{
					lockBehavior = IscCodes.isc_tpb_shared;
				}
				if (lockBehavior.HasValue)
					tpb.Append((int)lockBehavior);
			}
            if ((options.TransactionBehavior & FbTransactionBehavior.ReadCommitted) == FbTransactionBehavior.ReadCommitted)
            {
                tpb.Append(IscCodes.isc_tpb_read_committed);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.Autocommit) == FbTransactionBehavior.Autocommit)
            {
                tpb.Append(IscCodes.isc_tpb_autocommit);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.RecVersion) == FbTransactionBehavior.RecVersion)
            {
                tpb.Append(IscCodes.isc_tpb_rec_version);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.NoRecVersion) == FbTransactionBehavior.NoRecVersion)
            {
                tpb.Append(IscCodes.isc_tpb_no_rec_version);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.RestartRequests) == FbTransactionBehavior.RestartRequests)
            {
                tpb.Append(IscCodes.isc_tpb_restart_requests);
            }
            if ((options.TransactionBehavior & FbTransactionBehavior.NoAutoUndo) == FbTransactionBehavior.NoAutoUndo)
            {
                tpb.Append(IscCodes.isc_tpb_no_auto_undo);
            }
			
			return tpb;
		}
 internal async Task BeginTransaction(FbTransactionOptions options, AsyncWrappingCommonArgs async)
 {
     _transaction = await _connection.InnerConnection.Database.BeginTransaction(BuildTpb(options), async).ConfigureAwait(false);
 }
Exemple #20
0
        public Task <FbTransaction> BeginTransactionAsync(FbTransactionOptions options, string transactionName, CancellationToken cancellationToken = default)
        {
            CheckClosed();

            return(_innerConnection.BeginTransactionAsync(options, transactionName, cancellationToken));
        }
 public FbTransaction BeginTransaction(FbTransactionOptions options)
 {
     return this.BeginTransaction(options, null);
 }
 internal void BeginTransaction(FbTransactionOptions options)
 {
     _transaction = _connection.InnerConnection.Database.BeginTransaction(BuildTpb(options));
 }
Exemple #23
0
 internal async Task BeginTransactionAsync(FbTransactionOptions options, CancellationToken cancellationToken = default)
 {
     _transaction = await _connection.InnerConnection.Database.BeginTransactionAsync(BuildTpb(options), cancellationToken).ConfigureAwait(false);
 }
 /// <summary>
 /// 静的フィールドの初期化を行います。
 /// </summary>
 static Transaction()
 {
     Transaction.fbTransactionOption = new FbTransactionOptions();
 }
Exemple #25
0
        public FbTransaction BeginTransaction(FbTransactionOptions options, string transactionName)
        {
            CheckClosed();

            return(_innerConnection.BeginTransaction(options, transactionName));
        }
Exemple #26
0
 /// <summary>
 /// Осуществляет инициализацию работы с БД службы.
 /// </summary>
 public static void Init()
 {
     // Инициализируем подключение к базе данных
     _DB_FullFileName = AppDomain.CurrentDomain.BaseDirectory + "DEVICES.FB";
     _DB_ClientLibraryPath = AppDomain.CurrentDomain.BaseDirectory + "fbdb\\fbembed.dll";
     try
     {
         // Задаем параметры подключения
         FbConnectionStringBuilder conn_str = new FbConnectionStringBuilder();
         conn_str.ServerType = FbServerType.Embedded;
         conn_str.Charset = "WIN1251";
         conn_str.Dialect = 3;
         conn_str.Role = "";
         conn_str.Database = _DB_FullFileName;
         //conn_str.DataSource = "localhost";
         //conn_str.Port = 3050;
         //conn_str.ConnectionLifeTime = 0;
         //conn_str.Pooling = true;
         //conn_str.MinPoolSize = 0;
         //conn_str.MaxPoolSize = 50;
         conn_str.UserID = _DB_Login;
         conn_str.Password = _DB_Paswd;
         conn_str.ClientLibrary = _DB_ClientLibraryPath;
         conn_str.PacketSize = 16384;
         // Создаем подключение к БД
         FB_dbConnection = new FbConnection(conn_str.ToString());
         // Инициализируем и задаем параметры транзакций
         FB_dbReadTransactionOptions = new FbTransactionOptions();
         FB_dbReadTransactionOptions.TransactionBehavior = FbTransactionBehavior.Read | FbTransactionBehavior.ReadCommitted | FbTransactionBehavior.RecVersion;
         FB_dbCommitTransactionOptions = new FbTransactionOptions();
         FB_dbCommitTransactionOptions.TransactionBehavior = FbTransactionBehavior.NoWait | FbTransactionBehavior.ReadCommitted | FbTransactionBehavior.RecVersion;
     }
     catch (Exception exc)
     {
         // Делаем запись в журнал событий
         WinLog.Write(string.Format("Ошибка инициализации БД: ", exc.Message), System.Diagnostics.EventLogEntryType.Error);
         // Освобождаем ресурсы
         if (FB_dbConnection != null)
             FB_dbConnection.Dispose();
         FB_dbConnection = null;
     }
     // Устанавливаем признак того, что в данный момент транзакций нет
     IsLockedTransaction = false;
 }