Beispiel #1
0
 internal BedRow(BedTable table, IBedRecord original, BedRowState initialState, ITableStructure structure)
 {
     m_table     = table;
     m_fields    = new FieldRec[m_table.Structure.Columns.Count];
     m_original  = original;
     m_structure = structure;
     RowState    = initialState;
 }
Beispiel #2
0
 public void SetDataSource(BedTable table, int rowOffset)
 {
     FirstRowOffset = rowOffset;
     if (table != null)
     {
         table.BedConvertor = new BedValueConvertor(m_fmtSettings);
     }
     DataSource = table;
     ResizeColumns();
 }
Beispiel #3
0
        public BedTable GetFirstRows(int count)
        {
            var res = new BedTable(Structure);

            for (int i = 0; i < Math.Min(count, Rows.Count); i++)
            {
                res.AddRow(Rows[i]);
            }
            return(res);
        }
Beispiel #4
0
 public void SaveChanges(BedTable table, ISqlDumper dmp)
 {
     try
     {
         m_adapterByTable[table].SaveChanges(table, dmp);
     }
     catch (Exception err)
     {
         throw new DataError("DAE-00359", err);
     }
 }
Beispiel #5
0
 public void SaveChanges(BedTable table, ISaveDataProgress progress)
 {
     try
     {
         m_adapterByTable[table].SaveChanges(table, progress);
     }
     catch (Exception err)
     {
         throw new DataError("DAE-00360", err);
     }
 }
Beispiel #6
0
        public static BedTable ToBinaryTable(this DataTable table)
        {
            var      ts  = table.Columns.GetTableStructure("table");
            BedTable res = new BedTable(ts);

            foreach (DataRow row in table.Rows)
            {
                res.AddRow(new DataRecordAdapter(new DataRowAdapter(row), ts));
            }
            return(res);
        }
Beispiel #7
0
        public InMemoryTable(InMemoryTable oldTable, DataScript script)
        {
            Initialize();
            m_structure = new TableStructure(oldTable.Structure);
            BedTable bt = new BedTable(oldTable);

            bt.RunScript(script);
            foreach (IBedRecord rec in bt.Rows)
            {
                m_rows.Add(new ArrayDataRecord(rec));
            }
        }
Beispiel #8
0
        public BedTable LoadTableData(TablePageProperties props)
        {
            lock (m_directory)
            {
                BedTable table = new BedTable(m_table);

                int start = 0;
                int count = m_serializedRows;
                if (props.Count != null)
                {
                    count = props.Count.Value;
                }
                if (props.Start != null)
                {
                    start = props.Start.Value;
                }

                if (start >= m_serializedRows)
                {
                    return(table);
                }
                int curdic = start / BUFFER_SIZE, skiprec = start % BUFFER_SIZE;
                Errors.Assert(curdic < m_directory.Count);
                m_cache.Seek(m_directory[curdic], SeekOrigin.Begin);

                int          availtables = m_directory.Count - curdic;
                BinaryReader br          = new BinaryReader(m_cache);
                while (table.Rows.Count < count && availtables >= 1)
                {
                    ChunkInfo info = ChunkInfo.LoadInfo(br);
                    if (skiprec > 0)
                    {
                        int skipbytes = 0;
                        for (int i = 0; i < skiprec; i++)
                        {
                            skipbytes += info.Lengths[i];
                        }
                        m_cache.Seek(skipbytes, SeekOrigin.Current);
                    }
                    int rec = skiprec;

                    while (rec < info.Count)
                    {
                        table.AddRowInternal(BedTool.LoadRecord(br, m_table));
                        rec++;
                    }
                    availtables--;
                    skiprec = 0;
                }
                return(table);
            }
        }
        public static BedTable ToBinaryTable(this IBedReader reader, int?maximumRecords)
        {
            //ITableStructure ts = reader.GetTableStructure();
            BedTable dt         = new BedTable(reader.Structure);
            int      allow_recs = maximumRecords != null ? maximumRecords.Value : -1;

            while (reader.Read() && (maximumRecords == null || allow_recs > 0))
            {
                dt.AddRow(reader);
                allow_recs--;
            }
            return(dt);
        }
 void WantTable()
 {
     if (m_table == null)
     {
         if (m_loadFunc != null)
         {
             m_table = m_loadFunc(m_conn).ToBinaryTable();
         }
         if (m_loadBedFunc != null)
         {
             m_table = m_loadBedFunc(m_conn);
         }
     }
 }
Beispiel #11
0
        public BedTable Filter(Func <BedRow, bool> filter)
        {
            BedTable res = new BedTable(m_structure);

            res.m_convertor = m_convertor;
            foreach (var row in Rows)
            {
                if (filter(row))
                {
                    res.AddRow(row);
                }
            }
            return(res);
        }
Beispiel #12
0
 public void SaveChanges(BedTable table, ISaveDataProgress progress)
 {
     using (DbTransaction tran = m_conn.SystemConnection.BeginTransaction())
     {
         try
         {
             m_conn.RunScript(dmp => SaveChanges(table, dmp, progress), tran, null);
             tran.Commit();
         }
         catch
         {
             tran.Rollback();
             throw;
         }
     }
 }
Beispiel #13
0
        public void SaveChanges(BedTable table, ISqlDumper dmp, ISaveDataProgress progress)
        {
            if (IsReadOnly)
            {
                throw new InternalError("DAE-00020 BedAdapter is read only, can not save changes");
            }
            DataScript             script  = table.GetBaseModifyScript();
            MultiTableUpdateScript lscript = table.GetLinkedDataScript(m_structure.FullName);

            if (progress != null)
            {
                script.ReportCounts(progress);
                lscript.ReportCounts(progress);
            }
            dmp.UpdateData(m_structure, script, progress);
            dmp.UpdateData(lscript, progress);
        }
 public InMemoryTabularData(BedTable table)
 {
     m_table = table;
 }
Beispiel #15
0
 public void SaveChanges(BedTable table, ISqlDumper dmp)
 {
     SaveChanges(table, dmp, null);
 }
Beispiel #16
0
 internal BedRowCollection(BedTable table)
 {
     m_table = table;
 }
 public void SaveChanges(BedTable table, ISaveDataProgress progress)
 {
     throw new NotImplementedError("DAE-00273");
 }
Beispiel #18
0
        public BedTable LoadTableData(TablePageProperties props)
        {
            DateTime start = DateTime.Now;
            var      per   = props.Perspective;

            try
            {
                BedAdapter adapter;
                string     cmdtext;
                LoadTableDataProlog(props, out adapter, out cmdtext);
                using (var canc = Connection.AddOnCancel(adapter.CancelLoading))
                {
                    BedTable table = null;
                    try
                    {
                        table = adapter.LoadTableData(props.Start, props.Count, cmdtext);
                    }
                    catch (Exception err)
                    {
                        LoadTableDataPrologHandleError(props, err);
                    }
                    var    slen = DateTime.Now - start;
                    double len  = slen.TotalSeconds;
                    if (table != null)
                    {
                        ProgressInfo.Debug(Texts.Get("s_readed$rows$cols$len",
                                                     "rows", table.Rows.Count,
                                                     "cols", table.Structure.Columns.Count,
                                                     "len", len.ToString("0.00")));
                    }
                    m_adapterByTable[table] = adapter;
                    if (per != null)
                    {
                        table.ResultFields = per.Select.Columns;
                    }
                    if (LoadedDataInfo != null)
                    {
                        var ea = new LoadedTableInfoArgs();
                        ea.Duration = slen;
                        ea.Table    = table;
                        LoadedDataInfo(this, ea);
                    }
                    return(table);
                }
            }
            catch (Exception err)
            {
                // probably error in command, clear adapter so that it is recreated next time
                m_adapters.Remove(per ?? nullPer);

                if (LoadedDataInfo != null)
                {
                    var ea = new LoadedTableInfoArgs();
                    ea.Duration = DateTime.Now - start;
                    ea.Error    = err;
                    LoadedDataInfo(this, ea);
                }

                throw;
            }
        }
 public void SaveChanges(BedTable table, ISqlDumper dmp)
 {
     throw new NotImplementedError("DAE-00274");
 }
Beispiel #20
0
        public BedTable LoadTableData(int?start, int?count, string queryInstance)
        {
            int skipcount = 0;

            if (start != null)
            {
                skipcount = start.Value;
            }

            string sql = queryInstance;

            if (m_conn.Dialect.DialectCaps.RangeSelect && (skipcount > 0 || count != null))
            {
                sql       = m_conn.Dialect.GetRangeSelect(queryInstance, skipcount, count.Value);
                skipcount = 0;
            }
            else if (m_conn.Dialect.DialectCaps.LimitSelect && count != null)
            {
                sql = m_conn.Dialect.GetLimitSelect(queryInstance, skipcount + count.Value);
            }

            //WantMetadata();

            using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
            {
                try
                {
                    lock (m_currentCommandLock) m_currentCommand = cmd;
                    cmd.CommandText = sql;
                    CommandBehavior behaviour = CommandBehavior.Default;
                    if (!HasMetaData)
                    {
                        behaviour |= CommandBehavior.KeyInfo;
                    }
                    using (IBedReader reader = m_dda.AdaptReader(cmd.ExecuteReader(behaviour)))
                    {
                        if (!HasMetaData)
                        {
                            m_structure = reader.Structure;
                        }
                        if (m_structure == null)
                        {
                            return(null);
                        }
                        BedTable res = new BedTable(m_structure);
                        while (skipcount > 0)
                        {
                            if (!reader.Read())
                            {
                                return(res);
                            }
                            skipcount--;
                        }

                        while (count == null || res.Rows.Count < count.Value)
                        {
                            if (!reader.Read())
                            {
                                return(res);
                            }
                            res.AddRow(reader);
                        }

                        return(res);
                    }
                }
                catch (Exception err)
                {
                    err.Data["sql"] = sql;
                    m_conn.FillInfo(err.Data);
                    throw;
                }
                finally
                {
                    lock (m_currentCommandLock) m_currentCommand = null;
                }
            }
        }