Exemple #1
0
        private TransactionParameterBuffer BuildTpb(IsolationLevel isolationLevel)
        {
            TransactionParameterBuffer tpb = this.db.CreateTransactionParameterBuffer();

            tpb.Append(IscCodes.isc_tpb_version3);
            tpb.Append(IscCodes.isc_tpb_write);
            tpb.Append(IscCodes.isc_tpb_wait);

            /* Isolation level */
            switch (isolationLevel)
            {
            case IsolationLevel.Serializable:
                tpb.Append(IscCodes.isc_tpb_consistency);
                break;

            case IsolationLevel.RepeatableRead:
                tpb.Append(IscCodes.isc_tpb_concurrency);
                break;

            case IsolationLevel.ReadUncommitted:
                tpb.Append(IscCodes.isc_tpb_read_committed);
                tpb.Append(IscCodes.isc_tpb_rec_version);
                break;

            case IsolationLevel.ReadCommitted:
            default:
                tpb.Append(IscCodes.isc_tpb_read_committed);
                tpb.Append(IscCodes.isc_tpb_no_rec_version);
                break;
            }

            return(tpb);
        }
        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 #3
0
        private TransactionParameterBuffer BuildTpb(FbTransactionOptions options)
        {
            TransactionParameterBuffer tpb = new TransactionParameterBuffer();

            tpb.Append(IscCodes.isc_tpb_version3);

            if ((options & FbTransactionOptions.Consistency) == FbTransactionOptions.Consistency)
            {
                tpb.Append(IscCodes.isc_tpb_consistency);
            }
            if ((options & FbTransactionOptions.Concurrency) == FbTransactionOptions.Concurrency)
            {
                tpb.Append(IscCodes.isc_tpb_concurrency);
            }
            if ((options & FbTransactionOptions.Shared) == FbTransactionOptions.Shared)
            {
                tpb.Append(IscCodes.isc_tpb_shared);
            }
            if ((options & FbTransactionOptions.Protected) == FbTransactionOptions.Protected)
            {
                tpb.Append(IscCodes.isc_tpb_protected);
            }
            if ((options & FbTransactionOptions.Exclusive) == FbTransactionOptions.Exclusive)
            {
                tpb.Append(IscCodes.isc_tpb_exclusive);
            }
            if ((options & FbTransactionOptions.Wait) == FbTransactionOptions.Wait)
            {
                tpb.Append(IscCodes.isc_tpb_wait);
            }
            if ((options & FbTransactionOptions.NoWait) == FbTransactionOptions.NoWait)
            {
                tpb.Append(IscCodes.isc_tpb_nowait);
            }
            if ((options & FbTransactionOptions.Read) == FbTransactionOptions.Read)
            {
                tpb.Append(IscCodes.isc_tpb_read);
            }
            if ((options & FbTransactionOptions.Write) == FbTransactionOptions.Write)
            {
                tpb.Append(IscCodes.isc_tpb_write);
            }
            if ((options & FbTransactionOptions.LockRead) == FbTransactionOptions.LockRead)
            {
                tpb.Append(IscCodes.isc_tpb_lock_read);
            }
            if ((options & FbTransactionOptions.LockWrite) == FbTransactionOptions.LockWrite)
            {
                tpb.Append(IscCodes.isc_tpb_lock_write);
            }
            if ((options & FbTransactionOptions.ReadCommitted) == FbTransactionOptions.ReadCommitted)
            {
                tpb.Append(IscCodes.isc_tpb_read_committed);
            }
            if ((options & FbTransactionOptions.Autocommit) == FbTransactionOptions.Autocommit)
            {
                tpb.Append(IscCodes.isc_tpb_autocommit);
            }
            if ((options & FbTransactionOptions.RecVersion) == FbTransactionOptions.RecVersion)
            {
                tpb.Append(IscCodes.isc_tpb_rec_version);
            }
            if ((options & FbTransactionOptions.NoRecVersion) == FbTransactionOptions.NoRecVersion)
            {
                tpb.Append(IscCodes.isc_tpb_no_rec_version);
            }
            if ((options & FbTransactionOptions.RestartRequests) == FbTransactionOptions.RestartRequests)
            {
                tpb.Append(IscCodes.isc_tpb_restart_requests);
            }
            if ((options & FbTransactionOptions.NoAutoUndo) == FbTransactionOptions.NoAutoUndo)
            {
                tpb.Append(IscCodes.isc_tpb_no_auto_undo);
            }

            return(tpb);
        }
Exemple #4
0
        private TransactionParameterBuffer BuildTpb(FbTransactionOptions options)
        {
            TransactionParameterBuffer tpb = new TransactionParameterBuffer();

            tpb.Append(IscCodes.isc_tpb_version3);

            FbTransactionOptions[] o = (FbTransactionOptions[])Enum.GetValues(options.GetType());
            for (int i = 0; i < o.Length; i++)
            {
                FbTransactionOptions option = ((FbTransactionOptions)(o[i]));
                if ((options & option) == option)
                {
                    switch (option)
                    {
                    case FbTransactionOptions.Consistency:
                        tpb.Append(IscCodes.isc_tpb_consistency);
                        break;

                    case FbTransactionOptions.Concurrency:
                        tpb.Append(IscCodes.isc_tpb_concurrency);
                        break;

                    case FbTransactionOptions.Shared:
                        tpb.Append(IscCodes.isc_tpb_shared);
                        break;

                    case FbTransactionOptions.Protected:
                        tpb.Append(IscCodes.isc_tpb_protected);
                        break;

                    case FbTransactionOptions.Exclusive:
                        tpb.Append(IscCodes.isc_tpb_exclusive);
                        break;

                    case FbTransactionOptions.Wait:
                        tpb.Append(IscCodes.isc_tpb_wait);
                        break;

                    case FbTransactionOptions.NoWait:
                        tpb.Append(IscCodes.isc_tpb_nowait);
                        break;

                    case FbTransactionOptions.Read:
                        tpb.Append(IscCodes.isc_tpb_read);
                        break;

                    case FbTransactionOptions.Write:
                        tpb.Append(IscCodes.isc_tpb_write);
                        break;

                    case FbTransactionOptions.LockRead:
                        tpb.Append(IscCodes.isc_tpb_lock_read);
                        break;

                    case FbTransactionOptions.LockWrite:
                        tpb.Append(IscCodes.isc_tpb_lock_write);
                        break;

                    case FbTransactionOptions.ReadCommitted:
                        tpb.Append(IscCodes.isc_tpb_read_committed);
                        break;

                    case FbTransactionOptions.Autocommit:
                        tpb.Append(IscCodes.isc_tpb_autocommit);
                        break;

                    case FbTransactionOptions.RecVersion:
                        tpb.Append(IscCodes.isc_tpb_rec_version);
                        break;

                    case FbTransactionOptions.NoRecVersion:
                        tpb.Append(IscCodes.isc_tpb_no_rec_version);
                        break;

                    case FbTransactionOptions.RestartRequests:
                        tpb.Append(IscCodes.isc_tpb_restart_requests);
                        break;

                    case FbTransactionOptions.NoAutoUndo:
                        tpb.Append(IscCodes.isc_tpb_no_auto_undo);
                        break;
                    }
                }
            }

            return(tpb);
        }