Ejemplo n.º 1
0
        public int Execute(string sql, ref FbTransaction tr, bool commit_auto = true)
        {
            if (tr == null)
            {
                tr = GetTransaction(false);
            }

            var cmd         = new FbCommand(sql, conn, tr);
            var rowAffected = cmd.ExecuteNonQuery();

            if (commit_auto)
            {
                tr.CommitRetaining();
            }

            return(rowAffected);
        }
Ejemplo n.º 2
0
        //----------------------------------------------------------------------
        public void CommitRetainingTrans()
        {
            if (trans == null)
            {
                throw new Exception("Occurred transaction doesn't begin error in UlFirebird.RollbackTrans");
            }

            try
            {
                trans.CommitRetaining();
            }
            catch (Exception e)
            {
                string msg = string.Format("{0}\r\nOccurred commit transaction exception in UlFirebird.CommitRetainingTrans", e.ToString());
                throw new Exception(msg);
            }
        }
Ejemplo n.º 3
0
        //----------------------------------------------------------------------
        protected void CommitRetainingTrans(FbTransaction aTrans = null)
        {
            if (aTrans != null)
            {
                return;
            }

            if (trans == null)
            {
                throw new Exception("Occurred transaction doesn't begin error in UlDataSet.CommitRetainingTrans");
            }

            try
            {
                trans.CommitRetaining();
            }
            catch (Exception e)
            {
                string msg = string.Format("{0}\r\nOccurred commit retaining transaction exception in UlFirebird.CommitRetainingTrans", e.ToString());
                throw new Exception(msg);
            }
        }
Ejemplo n.º 4
0
        private FbTransaction GetTransaction(bool readable = true)
        {
            if (readable)
            {
                if (write_transaction != null)
                {
                    // if(conn.)
                    write_transaction.RollbackRetaining();
                    write_transaction.Dispose();
                }

                var tro = new FbTransactionOptions()
                {
                    TransactionBehavior = FbTransactionBehavior.Read | FbTransactionBehavior.ReadCommitted | FbTransactionBehavior.RecVersion
                };

                read_transaction = conn.BeginTransaction(tro);
                return(read_transaction);
            }
            else
            {
                if (read_transaction != null)
                {
                    read_transaction.CommitRetaining();
                    read_transaction.Dispose();
                }

                var tro = new FbTransactionOptions()
                {
                    TransactionBehavior = FbTransactionBehavior.NoWait | FbTransactionBehavior.ReadCommitted | FbTransactionBehavior.RecVersion
                };

                write_transaction = conn.BeginTransaction(tro);
                return(write_transaction);
            }
        }
Ejemplo n.º 5
0
        private void UpgradeTriggers(SyncDatabase db, SyncTableList tables)
        {
            db.Log.Debug(db.FMsg("Выполняется обновление текста триггеров..."));

            StringBuilder sb = new StringBuilder(100);

            foreach (SyncTable t in tables)
            {
                if (sb.Length > 0)
                {
                    sb.Append(",");
                }
                sb.Append("'");
                sb.Append(t.TableName);
                sb.Append("'");
            }

            if (sb.Length == 0)
            {
                return;
            }

            string triggers_disable_hook = "/*TRG_DIS*/if (rdb$get_context('USER_TRANSACTION', 'TRG_DISABLE') is not null) then exit;";

            // для триггеров архивации другая строчка (их не отключаем
            string triggers_disable_hook_arc = "/*TRG_DIS*/if (rdb$get_context('USER_TRANSACTION', 'TRG_DISABLE_ARC') is not null) then exit;";

            string        sql       = string.Format(@"select * from rdb$triggers
where rdb$system_flag = 0 and rdb$trigger_name not like 'CHECK%' and rdb$relation_name <> 'SYNC_LOG' and 
rdb$relation_name in ('', {0})", sb.ToString());
            FbTransaction trg_trans = db.Transaction as FbTransaction;

            //(db.Connection as FbConnection).BeginTransaction(FbTransactionOptions.NoWait | FbTransactionOptions.ReadCommitted);
            using (FbCommand cmd = new FbCommand(string.Empty, db.Connection as FbConnection, trg_trans))
            {
                cmd.CommandText = sql;
                using (FbDataReader reader = cmd.ExecuteReader())
                    while (reader.Read())
                    {
                        string trigger_name     = reader["RDB$TRIGGER_NAME"].ToString().Trim();
                        string trigger_source   = reader["RDB$TRIGGER_SOURCE"].ToString().Trim();
                        string l_trigger_source = trigger_source.ToLower();

                        string trg_hook = triggers_disable_hook;
                        if (trigger_name.StartsWith("T_SYNC$"))
                        {
                            trg_hook = triggers_disable_hook_arc;
                        }

                        // закладка для кредитного клиента
                        if ((db.Connection as FbConnection).ConnectionString.ToLower().Contains("kredclient") &&
                            trigger_source.ToLower().Contains("sp_write_log"))
                        {
                            trg_hook = triggers_disable_hook_arc;
                        }

                        if (!l_trigger_source.Contains(trg_hook.ToLower()))
                        {
                            int pos_begin = l_trigger_source.IndexOf("begin");
                            if (pos_begin >= 0)
                            {
                                trigger_source = trigger_source.Insert(pos_begin + 5, "\r\n" + trg_hook);

                                if ((trg_hook == triggers_disable_hook_arc) && trigger_source.Contains(triggers_disable_hook))
                                {
                                    trigger_source = trigger_source.Replace(triggers_disable_hook, string.Empty);
                                }

                                using (FbCommand cmd_alter = db.CreateCommand() as FbCommand)
                                {
                                    cmd_alter.CommandText = string.Format("ALTER TRIGGER {0}\r\n{1}",
                                                                          trigger_name, trigger_source);
                                    try
                                    {
                                        cmd_alter.ExecuteNonQuery();
                                        trg_trans.CommitRetaining();
                                    }
                                    catch (Exception ex)
                                    {
                                        trg_trans.RollbackRetaining();
                                        db.Log.Warn(string.Format(db.FMsg("Ошибка при обновлении текста триггера ({0}):  {1}"),
                                                                  trigger_name, ex.Message));
                                    }
                                }
                            }
                        }
                    }
                trg_trans.CommitRetaining();
            }

            db.Log.Debug(db.FMsg("Обновление текста триггеров выполнено."));
        }