Exemple #1
0
        public override async Task <bool> SaveItem(DBItem item, DBTransaction transaction)
        {
            if ((item.UpdateState & DBUpdateState.Delete) == DBUpdateState.Delete &&
                item is DBLogItem logItem && FileLOBKey is DBLogColumn logColumn)
            {
                var lob     = item.GetValue <uint?>(logColumn);
                var current = logItem.BaseItem?.GetValue <uint?>(logColumn.BaseColumn);
                if (lob != null && lob != current)
                {
                    var qquery = new QQuery(this);
                    qquery.BuildParam(FileLOBKey, lob);
                    if (!Load(qquery).Any(p => p != item))
                    {
                        try
                        {
                            using (var transactionDeleteLOB = new DBTransaction(transaction.DbConnection, transaction.Caller))
                            {
                                await System.DeleteLOB(lob.Value, transactionDeleteLOB);

                                transactionDeleteLOB.Commit();
                            }
                        }
                        catch (Exception ex)
                        {
                            Helper.OnException(ex);
                        }
                    }
                }
            }
            return(await base.SaveItem(item, transaction));
        }
Exemple #2
0
        public async Task ExportTable(ExportProgressArgs ea)
        {
            try
            {
                DBETable table = ea.Table;
                if ((mode & ExportMode.Patch) != ExportMode.Patch)
                {
                    table.SourceTable.Clear();
                    table.TargetTable.Clear();
                }
                using (var transacton = new DBTransaction(table.SourceTable.Connection))
                {
                    ea.Current     = 0;
                    ea.Count       = table.SourceTable.GetRowCount(transacton, table.Query);
                    ea.Description = null;
                    OnExportProgress(ea);

                    using (transacton.Reader = transacton.ExecuteQuery(table.SourceTable.CreateQuery(table.Query, null), DBExecuteType.Reader) as IDataReader)
                    {
                        table.SourceTable.CheckColumns(transacton);
                        while (transacton.Reader.Read())
                        {
                            if (ea.Cancel)
                            {
                                transacton.Cancel();
                                return;
                            }
                            var row    = table.SourceTable.LoadItemFromReader(transacton);
                            var newRow = ExportRow(table, row);

                            await table.TargetTable.SaveItem(newRow, null);

                            ea.Current++;
                            ea.Row = newRow;

                            OnExportProgress(ea);

                            if ((mode & ExportMode.Patch) != ExportMode.Patch)
                            {
                                table.SourceTable.Clear();
                                table.TargetTable.Clear();
                            }
                        }
                        transacton.Reader.Close();
                    }
                    transacton.Commit();
                }
            }
            catch (Exception ex)
            {
                ea.Exception = ex;
                OnExportProgress(ea);
            }
        }
Exemple #3
0
 public object ExecuteQuery(string query, bool noTransaction = false, DBExecuteType type = DBExecuteType.Scalar)
 {
     if (string.IsNullOrEmpty(query))
     {
         return(null);
     }
     using (var transaction = new DBTransaction(this, null, noTransaction))
     {
         var result = transaction.ExecuteQuery(transaction.AddCommand(query), type);
         transaction.Commit();
         return(result);
     }
 }
Exemple #4
0
        public async Task Save()
        {
            using (var transaction = new DBTransaction(Table.Connection))
            {
                try
                {
                    await Save(transaction);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    Helper.OnException(ex);
                    transaction.Rollback();
                }
            }
        }